Time World
1/18/2009 9:57:00 PM
[Note: parts of this message were removed to make it a legal post.]
2009/1/18 Raj Singh <neeraj.jsr@gmail.com>
> >> c1 = 'hello'
> >> eval c1
> NameError: undefined local variable or method `hello' for main:Object
>
> >> c2 = 'hello #{hi}'
> => "hello \#{hi}"
> >> eval c2
> NameError: undefined local variable or method `hello' for main:Object
>
> >> c3 = '#{hi} hello'
> => "\#{hi} hello"
> >> eval c3
> => nil
>
>
> My question is why the eval of c3 is returning nil. It should fail
> saying that undefined local variable just as it did in the case of c2 ?
It's evaluated as a comment:
#hi hello
If you want #{hi} to be replaced by the content of the variable hi, you
should use double quotes:
c4 = "#{hi} hello"