有时候要一组字符串能能够动态地执行,ruby中的eval方法就提供了这样的功能 语法: eval( 可执行字符串) 使用举例: b="true" c="false" str ="if a==1 then puts '输出:#{b}'else puts '输出:#{c}' end" eval(str) 输出结果为:"true" 相关文章: