【发布时间】:2010-11-28 04:33:11
【问题描述】:
def test_method
["a", "b", "c"].map {|i| yield(i) }
end
如果我这样调用 test_method:
p test_method {|i| i.upcase }
# => ["A", "B", "C"]
为什么我需要在块中使用 {|i|},而不是这样说:
p test_method { i.upcase }
我之所以这么认为是因为在 test_method 中调用 yield 时,我们已经有了一个 {|i|}
["a", "b", "c"].map {|i| yield(i) }
【问题讨论】: