Matz 这是在向 Haskell 致敬
The Evolution of a Haskell Programmer http://www.willamette.edu/~fruehr/haskell/evolution.html
深有感触啊。还是在盒子里钻不出来。佩服!
def fact(n, hash)
(1..n).reduce(hash[:method])
end
p fact(10, method: :+) # => 55
p fact(10, method: :*) # => 3628800
直接通过哈希传递方法,哈哈。
是啊,还是没有跳出盒子啊!(Out of Box).
不过,对于熟悉命名参数的人,我那种用法更好懂一些。
p fact(10, :method => :+) p fact(10, :method => :*)