From: MonkeeSage Date: 2008-01-03T13:04:59+09:00 Subject: Re: change the symbol in an interpolated string value? On Jan 2, 9:23 pm, scoot...@hotmail.com wrote: > PROBLEM: > I would like to be able to change the symbol in an interpolated string > value. > For example: > > # before > whoever = "World"; > message = "Hello #{whoever}"; > puts message; > > # after > whoever = "World"; > ## message = "Hello @{whoever}"; ## one arbitrary example > ## message = "Hello ${whoever}"; ## another example > ## message = "Hello ???{whoever}"; ## yet another > ## message = "Hello ___whoever___"; ## or even yet another, no > braces this time > puts message; > > I would like to be able to make it so any of the commented-out > versions could work, just as the "before" version works. > > What's the ruby-way of doing this? You can do it with regular expressions or a parser, but you shouldn't...it will be *much* slower (and I mean like a gabazillion times slower), and almost certainly less robust (e.g., handling nested symbols), than the built-in interpolation syntax. Why do you need a different syntax? Regards, Jordan