【发布时间】:2013-06-23 05:02:38
【问题描述】:
inner_method 只在outer_method 内被调用,其参数将始终与outer_method 相同。
这行得通:
def outer_method(word)
inner_method(word)
puts word + " are like candy."
end
def inner_method(same_word)
puts "I really love " + same_word + "!"
end
outer_method("onions")
但这不是:
def outer_method(word)
inner_method
puts word + "tastes like candy."
end
def inner_method
puts "I really love " + word + "!"
end
outer_method("onions")
inner_method 对word 的引用似乎没有被outer_method 注册。有没有更好的方法来做到这一点?
(我意识到在上面的例子中没有理由有一个单独的inner_method;为了清楚起见,这被简化了)
【问题讨论】: