From: David Alan Black Date: 2001-10-28T21:01:59+09:00 Subject: [ruby-talk:23676] Re: How to get a String to interpolate itself? Hello -- On Sun, 28 Oct 2001, Phil Tomson wrote: > So, in order to get it to work you would have to pass a binding in to the > interpolate method: > > class String > def interpolate(bind) > eval ("\"#{self.to_s}\"",bind) > end > end > var = 99 > bstr = 'now try this: #{var}' > p bstr.interpolate( binding()) > > Now it will work, but it's a bit nasty passing in the binding, couldn't > there be some bad consequences of this? Any other ideas? (maybe we could > just pass in a list of variables and their values to interpolate for). I respectfully submit that this is, to a large extent, a solution in search of a problem. I could be wrong... but, especially if it's going to involve the, to me, very awkward syntax of passing in variables by name and/or bindings, any time it's used it's probably just a sign that something in the program needs to be reorganized. (I know the same can be argued for the use of "eval" in general :-) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav