From: Bill Kelly Date: 2005-02-08T02:23:33+09:00 Subject: Re: delayed string interpolation From: "Navindra Umanee" > Bill Kelly 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("< > 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