String interpolation at a later stage

x = 'hello'
y = '#{x} world'

desired result = 'hello world'

Please note that variable y has the string interpolation code under
single quotes.

I have these two values x and y. And with that I need to get to the
desired result. Any suggestion on how to do that.

I tried eval y but that won't work because world is not a variable.

···

--
Posted via http://www.ruby-forum.com/.

* Raj Singh <neeraj.jsr@gmail.com> [2009-01-17 00:41:54 +0900]:

x = 'hello'
y = '#{x} world'

desired result = 'hello world'

Please note that variable y has the string interpolation code under
single quotes.

I have these two values x and y. And with that I need to get to the
desired result. Any suggestion on how to do that.

I tried eval y but that won't work because world is not a variable.

eval %Q["#{y}"]

Jan

···

--
Posted via http://www.ruby-forum.com/\.

--
jan=callcc{|jan|jan};jan.call(jan)

try:
z = '"' + y + '"'
zz = eval z

···

On Jan 16, 10:41 am, Raj Singh <neeraj....@gmail.com> wrote:

x = 'hello'
y = '#{x} world'

desired result = 'hello world'

Please note that variable y has the string interpolation code under
single quotes.

I have these two values x and y. And with that I need to get to the
desired result. Any suggestion on how to do that.

I tried eval y but that won't work because world is not a variable.
--
Posted viahttp://www.ruby-forum.com/.

This might not be exactly what you were asking for but might be helpful none the less:

x = 'hello'
lazy = lambda {"#{x} world"}

result = lazy.call
result = lazy

# or maybe even..

def lazy.to_s
   call
end

puts lazy # hello world

x = 'goodbye'

puts lazy # goodbye world

···

On Jan 16, 2009, at 10:41 AM, Raj Singh wrote:

x = 'hello'
y = '#{x} world'

desired result = 'hello world'