On Jun 2, 2011, at 9:44 AM, Peter Zotov wrote:

> On Thu, 2 Jun 2011 16:12:37 +0900, Chad Perrin wrote:
>> On Thu, Jun 02, 2011 at 04:02:31PM +0900, Peter Zotov wrote:
>>> 
>>> There is no separate method in Ruby which does the variable
>>> substitution.
>>> This functionality is hardcoded into lexer and parser.
>> 
>> I wonder how much that changes in the Rubinius implementation.
> 
> Yes, I thought about Rubinius too. It nevertheless uses lexer and parser,
> and amount of changes to code will be comparable IMO.

I don't think so. Literals are never "constructed", so there is no step
you could hook into. There is also no way to delay the interpolation step,
which is the second big question usually asked in this context.

What you can do, is using sprintf-substitution: 

   "%{firstname}, %{lastname}" % {:firstname => "Florian", 
                                  :lastname => "Gilcher"}
    # => "Florian Gilcher"

It doesn't save you any characters, though. Another way would be:

    "%s %s" % ["Florian", "Gilcher"]

Shorter, if you like it.

If you really want to, you could write your own, similar substitution,
but I am not sure whether thats work worth doing.

Regards,
Florian Gilcher