>> al = lambda { |a,b,c| b } >> bl = lambda { |(a,b,c)| b } >> list = [[1,1,1], [2,2,2], [3,3,3], [4,0,4]] >> list.sort_by &al ArgumentError: wrong number of arguments (1 for 3) from (irb):1:in `block in irb_binding' from (irb):4:in `each' from (irb):4:in `sort_by' >> list.sort_by &bl => [[4, 0, 4], [1, 1, 1], [2, 2, 2], [3, 3, 3]]
The view illustrates why they did it.
The reason for the Ruby change is that they are trying to make lambda compatible with regular methods:
>> def test(a,b,c); b; end >> test [1,2,3] ArgumentError: wrong number of arguments (1 for 3) from (irb):16:in `test'
A good way to get around the not-so-pretty syntax is to use the new and brilliant Stab tm operator :
cl = ->(a, b, c) { b }
source share