Taisuke Yamada
4/22/2005 4:42:00 PM
Yes, what I was looking for is 'perfect interpolation on demand'
that'll work whatever content is in interpolated string. I guess
eval("<<END_REEVAL\n" + self + "\nEND_REEVAL\n", b)
is the best (and robust) solution available as you can choose
random string that probably won't show up in interpolated string.
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.
BTW, I'm using this on-demand interpolation to supply options
dynamically to random shell commands read from configuration
file. Using template processing library was bit overkill, so
I went with eval-based one liner to do the job.
> I guess what Taisuke Yamada want is 'interpolation on demand', as opposed to
> interpolation when the string is first read by the ruby interpreter. This is
> needed when you want to interpolate strings that are builded from external
> sources. This subject was actually already discussed in ruby-talk/129959
> (delayed string interpolation)