[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: can erb produce erb?

Tim Pease

4/6/2007 7:07:00 PM

On 4/6/07, talkin ruby <rubytalk.heidmotron@gmail.com> wrote:
> just wondering if you could do something like this...
>
> ERB.new( some_erb_string ).result # '<%= result %>' another erb template
>
> so that way the result could be processed by another ERB.new
>

You are an evil and twisted individual! ;)

To answer your question, though, sure! ERb can do that.

require 'erb'

@blah = '<%= @not_blah %>'
ERB.new( "blah <%= @blah %>" ).result #=> "blah <%= @not_blah %>"


Blessings,
TwP

6 Answers

Ken Bloom

4/8/2007 2:09:00 AM

0

On Sat, 07 Apr 2007 04:07:16 +0900, Tim Pease wrote:

> On 4/6/07, talkin ruby <rubytalk.heidmotron@gmail.com> wrote:
>> just wondering if you could do something like this...
>>
>> ERB.new( some_erb_string ).result # '<%= result %>' another erb
>> template
>>
>> so that way the result could be processed by another ERB.new
>>
>>
> You are an evil and twisted individual! ;)
>
> To answer your question, though, sure! ERb can do that.
>
> require 'erb'
>
> @blah = '<%= @not_blah %>'
> ERB.new( "blah <%= @blah %>" ).result #=> "blah <%= @not_blah %>"

If you really want to be evil and twisted, what's the smallest self-
reproducing erb program you can write that doesn't read its own file.

The following solution is illegal:
<%= open(__FILE__){|f| f.read} %>

--Ken

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Alex Young

4/8/2007 7:30:00 AM

0

Ken Bloom wrote:
> On Sat, 07 Apr 2007 04:07:16 +0900, Tim Pease wrote:
>
>> On 4/6/07, talkin ruby <rubytalk.heidmotron@gmail.com> wrote:
>>> just wondering if you could do something like this...
>>>
>>> ERB.new( some_erb_string ).result # '<%= result %>' another erb
>>> template
>>>
>>> so that way the result could be processed by another ERB.new
>>>
>>>
>> You are an evil and twisted individual! ;)
>>
>> To answer your question, though, sure! ERb can do that.
>>
>> require 'erb'
>>
>> @blah = '<%= @not_blah %>'
>> ERB.new( "blah <%= @blah %>" ).result #=> "blah <%= @not_blah %>"
>
> If you really want to be evil and twisted, what's the smallest self-
> reproducing erb program you can write that doesn't read its own file.
>
> The following solution is illegal:
> <%= open(__FILE__){|f| f.read} %>
I think you mean "what's the smallest non-trivial self-reproducing erb
program...":

irb(main):012:0> ERB.new(' ').result
=> " "
irb(main):013:0> ERB.new('').result
=> ""

:-)

--
Alex

Alex Young

4/8/2007 9:04:00 AM

0

Ken Bloom wrote:
> On Sat, 07 Apr 2007 04:07:16 +0900, Tim Pease wrote:
>
>> On 4/6/07, talkin ruby <rubytalk.heidmotron@gmail.com> wrote:
>>> just wondering if you could do something like this...
>>>
>>> ERB.new( some_erb_string ).result # '<%= result %>' another erb
>>> template
>>>
>>> so that way the result could be processed by another ERB.new
>>>
>>>
>> You are an evil and twisted individual! ;)
>>
>> To answer your question, though, sure! ERb can do that.
>>
>> require 'erb'
>>
>> @blah = '<%= @not_blah %>'
>> ERB.new( "blah <%= @blah %>" ).result #=> "blah <%= @not_blah %>"
>
> If you really want to be evil and twisted, what's the smallest self-
> reproducing erb program you can write that doesn't read its own file.
>
> The following solution is illegal:
> <%= open(__FILE__){|f| f.read} %>

Drat. This nearly works:

<%=s=";\"<%=s=\#{s.inspect}\#{s}\"%\>";"<%=s=#{s.inspect}#{s}"%>

The only reason it doesn't is that ERB barfs on '%>' in a string inside
a <%= %> block, while String#inspect ignores it. This requires... trickery.

Luckily, we have trickery on hand. When in doubt, reverse the data:

<%=s=">%\"}esrever.s{#}tcepsni.s{#=s=%<\";";"<%=s=#{s.inspect}#{s.reverse}"%>

That's 77 characters by my count. 77 characters of pure, twisted, evil :-)

--
Alex

Ken Bloom

4/8/2007 4:52:00 PM

0

On Sun, 08 Apr 2007 16:30:11 +0900, Alex Young wrote:

> Ken Bloom wrote:
>> On Sat, 07 Apr 2007 04:07:16 +0900, Tim Pease wrote:
>>
>>> On 4/6/07, talkin ruby <rubytalk.heidmotron@gmail.com> wrote:
>>>> just wondering if you could do something like this...
>>>>
>>>> ERB.new( some_erb_string ).result # '<%= result %>' another erb
>>>> template
>>>>
>>>> so that way the result could be processed by another ERB.new
>>>>
>>>>
>>> You are an evil and twisted individual! ;)
>>>
>>> To answer your question, though, sure! ERb can do that.
>>>
>>> require 'erb'
>>>
>>> @blah = '<%= @not_blah %>'
>>> ERB.new( "blah <%= @blah %>" ).result #=> "blah <%= @not_blah %>"
>>
>> If you really want to be evil and twisted, what's the smallest self-
>> reproducing erb program you can write that doesn't read its own file.
>>
>> The following solution is illegal:
>> <%= open(__FILE__){|f| f.read} %>
> I think you mean "what's the smallest non-trivial self-reproducing erb
> program...":
>
> irb(main):012:0> ERB.new(' ').result
> => " "
> irb(main):013:0> ERB.new('').result
> => ""

Come to think of it, ERB is way too easy a language. You have to define
non-trivial to mean "includes a <% and a %>"

--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...

Christian Neukirchen

4/9/2007 12:57:00 PM

0

Ken Bloom <kbloom@gmail.com> writes:

> On Sun, 08 Apr 2007 16:30:11 +0900, Alex Young wrote:
>
>> Ken Bloom wrote:
>>> On Sat, 07 Apr 2007 04:07:16 +0900, Tim Pease wrote:
>>>
>>>> On 4/6/07, talkin ruby <rubytalk.heidmotron@gmail.com> wrote:
>>>>> just wondering if you could do something like this...
>>>>>
>>>>> ERB.new( some_erb_string ).result # '<%= result %>' another erb
>>>>> template
>>>>>
>>>>> so that way the result could be processed by another ERB.new
>>>>>
>>>>>
>>>> You are an evil and twisted individual! ;)
>>>>
>>>> To answer your question, though, sure! ERb can do that.
>>>>
>>>> require 'erb'
>>>>
>>>> @blah = '<%= @not_blah %>'
>>>> ERB.new( "blah <%= @blah %>" ).result #=> "blah <%= @not_blah %>"
>>>
>>> If you really want to be evil and twisted, what's the smallest self-
>>> reproducing erb program you can write that doesn't read its own file.
>>>
>>> The following solution is illegal:
>>> <%= open(__FILE__){|f| f.read} %>
>> I think you mean "what's the smallest non-trivial self-reproducing erb
>> program...":
>>
>> irb(main):012:0> ERB.new(' ').result
>> => " "
>> irb(main):013:0> ERB.new('').result
>> => ""
>
> Come to think of it, ERB is way too easy a language. You have to define
> non-trivial to mean "includes a <% and a %>"

irb(main):001:0> ERB.new('>%%<').result
=> ">%%<"

> Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

y2kbugxp90

4/10/2007 6:05:00 PM

0

On 4/9/07, Christian Neukirchen <chneukirchen@gmail.com> wrote:
> Ken Bloom <kbloom@gmail.com> writes:
> > Come to think of it, ERB is way too easy a language. You have to define
> > non-trivial to mean "includes a <% and a %>"
>
> irb(main):001:0> ERB.new('>%%<').result
> => ">%%<"
>
> > Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
> --
> Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...
>

Hey, that doesn't count! It doesn't contain '<%' or '%>'. How about this:

<%=File.new($FILENAME).readlines%>