From: "David A. Black" Date: 2005-04-23T23:07:55+09:00 Subject: Re: Clean way to dynamically expand string with "#{expression}"? Hi -- On Sat, 23 Apr 2005, Douglas Livingstone wrote: > On 4/23/05, dm1 wrote: >>> >>> Many interpolation code, including mine and several people >>> suggested will break if '"' or certain string is contained >>> in string to interpolate. >>> >>> Practically, it doesn't need to be perfect, but it was my >>> technical interest that there may be better way to do it. >>> Above code is cleaner and more robust, so I'll go with it. >>> Thanks for the pointer. >>> >> >> I do share that technical interest. I really wonder if there is a one liner >> for 'perfect interpolation on demand'. Everything i can think of is a bit >> longer. Let the quest continue :) >> > > The perfection might look something like this: > > "string with #{data}" == 'string with #{data}'.interpolate > > "abc" would just be syntax sugar for 'abc'.interpolate I think you'd lose a lot of speed adding a method call to string literals. I also don't think one would want the whole profile of string behavior to be built up from a pretty marginal, fragile, eval-based use case. The whole idea of delaying evaluation leads to things like coupling of local variable names (one method knowing what another's local variables will be called), which is pretty unscaleable and shaky. It's better to leave this kind of thing in the realm of "doing it is hard enough that we won't do it much" :-) David -- David A. Black dblack@wobblini.net