From: "Navindra Umanee" <navindra / cs.mcgill.ca>
> Bill Kelly <billk / cts.com> wrote:
> > I dunno if this counts as elegant or not, :)
> > but a couple years ago, I used:
> > 
> > class String
> >   def reeval(b = TOPLEVEL_BINDING)
> >     eval(%Q{<<"END_REEVAL"\n} + self + "\nEND_REEVAL\n", b)
> >   end
> > end
> 
> I have to say this is such a really neat hack...  it says so much
> about Ruby too.

Thanks!  And, indeed: thanks Matz !!  =D

> I had a hard time understanding it until I realised that the first
> END_REEVAL doesn't need to be in quotes.  Writing it as:
> 
>     eval("<<END_REEVAL\n" + self + "\nEND_REEVAL\n", b)
> 
> seems to work just as well.  Any reason you did it that way?

I'm guessing I got into the habit early on to remind
myself that ruby lets you specify single-quote semantics
if you want them, like:

x = <<'ENDTEXT'
now things like \n are literal
as they would be in 'single quote' strings
ENDTEXT

So I probably used <<"END_REEVAL" trying to be specific
about my request for double-quote semantics.... However
it seems to have just become a habit.  :)  Maybe I'll
stop doing it... Hehe..


Regards,

Bill