From: Dominik Bathon Date: 2006-01-05T07:07:37+09:00 Subject: Re: blk.call vs. yield (possible bug?) On Wed, 04 Jan 2006 19:57:08 +0100, wrote: > I think it has something to do with the Proc/lambda difference. When > you grab the block into a variable, it becomes a Proc object. > Otherwise it behaves like a lambda: > > irb(main):001:0> pr = Proc.new {|a,| a } > => # > irb(main):002:0> la = lambda {|a,| a } > => # > irb(main):003:0> pr.call([1,2]) > => 1 > irb(main):004:0> la.call([1,2]) > => [1, 2] > > I haven't tried all of them, but I strongly suspect you'll find that > all the behavior you're finding goes back to this. Yes, this is one cause, but I think the real "problem" is the one-array-on-the-right-side-special-case of multiple assignment: >> a,b,c = [1,2,3] => [1, 2, 3] >> [a,b,c] => [1, 2, 3] while >> a,b,c = [1,2,3], 1 => [[1, 2, 3], 1] >> [a,b,c] => [[1, 2, 3], 1, nil] I have investigate a bit in the source and I think what happens is that for "Proc.new {|a,| a }" the multiple assignment is done like: >> a, = [1,2]; a => 1 while for "lambda {|a,| a }" the multiple assignment is done like: >> a, = *[[1,2]]; a => [1, 2] They would be equivalent, if there wouldn't be the above mentioned special case... Of course this special case is useful, for example for multiple return values from a method, if it was not there one would have to write "a, b = *meth()" instead of "a, b = meth()"... Well, let's see what the future will bring, I think Matz said something about simplifying multiple assignment on RubyConf 05. Dominik