David A. Black wrote: > Hi -- > > On Thu, 8 Oct 2009, 7stud -- wrote: > >> p x >> >> --output:-- >> `test': wrong number of arguments (1 for 2) (ArgumentError) >> from r1test.rb:19 > > Lambda-flavored Proc objects are fussier about arity than > non-lambda-flavored ones. For example: > > def test > yield(1) > end > > test(&proc {|x,y| puts "Will get here in 1.9.1"}) > test(&lambda {|x,y| puts "Won't get here in 1.9.1"}) > > Output: > > Will get here in 1.9.1 > -:2:in `test': wrong number of arguments (1 for 2) (ArgumentError) > > So the lambda is more method-like in this particular respect than the > non-lambda Proc (since methods, likewise, care about arity). > > Ok. I get that. What I don't understand is how a yield statement decides how to distribute its arguments to the parameter variables specified for a block. In a method call, you have to use * to 'explode' an array into its individual elements, which will cause the individual elements to be assigned to the various parameter variables. yield seems to act differently. In one case, it assigns a whole array to a single parameter variable, and in another case it explodes the array into its individual elements and assigns the elements to the parameter variables. -- Posted via http://www.ruby-forum.com/.