我正在阅读pickaxe 1.9,作者像这样使用lambda:
bo = lambda {|param| puts "You called me with #{param}"}
bo.call 99 => 'You called me with 99'
bo.call "cat" => 'You called me with cat'
我的问题是:这比仅仅定义一个做同样事情的方法有什么更好/更差/不同?像这样:
def bo(param)
puts "You called me with #{param}"
end
bo("hello") => 'You called me with hello'
对我来说,lambda 语法似乎更令人困惑,更像意大利面条。