Why does this eval not work in Ruby
- by Anil
Can you explain this?
I want to eval values and calculations from two different sources. One source gives me the following info(programmatically):
'a = 2'
The second source gives me this expression to evaluate:
'a + 3'
This works:
a = 2
eval 'a + 3'
This also works:
eval 'a = 2; a + 3'
But what I really need is this, and it doesn't work:
eval 'a = 2'
eval 'a + 3'
I would like to understand the difference, and how can I make the last option work.
Thanks for your help.