On Wed, Jun 1, 2011 at 1:15 AM, Ilias Lazaridis <ilias / lazaridis.com> wrote:
> ruby 1.9
>
> prints "#{name} has 5 credits"
>
> Is there any *existent* library (ruby 1.9) availbale, which enables an
> alternative variable substitution, like e.g.
>
> prints "&name has 5 credits"

I don't know of anything that that modifies the behavior of String
that way, and changing the semantics of string literals is probably a
bad idea for all kinds of reasons, in the same way as changing the
semantics of integer literals so that 2 no longer represented the
integer between 1 and 3 would be.

On the other hand, Ruby has a wide variety of templating libraries
that will let you interpolate into strings in lots of different ways,
though you need to pass the string to a method of the templating
engine rather than just write a string literal that gets interpreted
in a manner that differs from normal Ruby evaluation.

Also, as you are probably aware (though newbies reading may not be),
Ruby already provides a shortcut interpolation of the kind you ask
for, but only for instance variables, not locals (e.g., instead of
"@foo is #{@foo}" you can use "@foo is #@foo".)