On 17 mayo, 01:33, Pe, Botp <b... / delmonte-phil.com> wrote:
> # irb(main):005:0> greeting="hi, #{"Ms "+name.capitalize}"
> # => "hi, Ms Aure"
>
> sorry, was too fast on the last example; should be..
>
> irb(main):006:0> greeting="hi, #{name="Anne";"Ms "+name.capitalize}"
> => "hi, Ms Anne"

I'm trying to do some metaprogramming and I need to apply some
operation to all the strings that are interpolated. But I can't change
the interpolation. In the example, I would like that "hi, #{name}" to
evaluate to "hi, AURE" instead of "hi, Aure". I know that inside the
#{} "operator" I can put any ruby code, so "hi, #{name.capitalize}"
would evaluate to what I want.

But I want it to execute code that I DON'T write there. Ideally, there
should be a method hook or something to change the way the
interpolation works. But I couldn't find it :(.  May be a different
example may be more clear. How can I do to write to a file all the
strings generated via interpolations (id est, all the strings that are
generated evaluating the different #{} "operators" in a program)?

Thanks,
Aureliano.