From: Robert Klemme Date: 2009-10-08T05:30:09+09:00 Subject: Re: Why I can not use my own blocks in 1.9? On 10/07/2009 12:48 PM, Florian Frank wrote: > Ivan Samonov wrote: >> Example: >> 1.8.7: >> a = lambda {|x,y| x <=> y} >> [1,2,3].max(&a) # => 3 >> 1.9.1: >> z = lambda {|x,y| x <=> y} >> [3,2,1].max(&z) # => ArgumentError: wrong number of arguments (1 for 2) >> >> wtf? >> > lambda does arity checking in 1.9 as opposed to proc that doesn't (they > aren't synonymous anymore). You can work around this problem by using > this definition for the order predicate: > > z = proc { |x,y| x <=> y} > > 1.9 obviously just passes an array to the block via rb_yield which used > to make sense in 1.8. But now using rb_yield_values probably would be > better to give users a hint about the expected predicate. This has worked in 1.9.0: irb(main):001:0> RUBY_VERSION => "1.9.0" irb(main):002:0> l = lambda {|a,b| a <=> b} => # irb(main):003:0> [3,2,1].sort(&l) => [1, 2, 3] Darn, I wasn't aware that the 1.9 on ubuntu is that old. Looks like I need to do a manual build. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/