本质上我想知道是否thefollowing可以在Ruby中完成。例如:defbar(symbol)#magiccodegoeshere,itoutputs"a=100"enddeffooa=100bar(:a)end 最佳答案 您必须将foo的上下文传递给bar:deffooa=100bar(:a,binding)enddefbar(sym,b)puts"#{sym}is#{eval(sym.to_s,b)}"end 关于ruby-你能在Ruby调用者的上下文中评估代码吗?,我们在Sta
选择有意义。但是有人可以向我解释.detect吗?我不明白这些数据。>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,4)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,6)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(3,7)}=>3>>[1,2,3,4,5,6,7].detect{|x|x.between?(2,7)}=>2>>[1,2,3,4,5,6,7].detect{|x|x.between?(1,7)}=>1>>[1,2,3,4,5,6,7].detect{|x