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.

How is it that both the following calls to test() work:

def test
  yield [10, "red"]
end

test {|x| p x}
puts

test do |x, y|
  p x
  puts "--"
  p y
end

--output:--
[10, "red"]

10
--
"red"


After all, this doesn't work:

def test(x, y)
  p x
  p y
end

test([10, "red"])

--output:--
`test': wrong number of arguments (1 for 2) (ArgumentError)
        from r1test.rb:19

-- 
Posted via http://www.ruby-forum.com/.