有时候要一组字符串能能够动态地执行,ruby中的eval方法就提供了这样的功能
a = 1
b = " true "
c = " false "
str = "
if a == 1 then
puts ' 输出:#{b} '
else
puts ' 输出:#{c} '
end
"
eval(str)
输出结果为:"true"
http://hi.baidu.com/alivio/blog/item/5e078f526a4b5a3743a75bf8.html
http://www.infoq.com/cn/articles/eval-options-in-ruby