From: "Wolfgang Nádasi-Donner" Date: 2008-10-22T21:25:59+09:00 Subject: [ruby-core:19443] Re: Now that lambda has more powerful arguments... Dave Thomas schrieb: > > On Oct 21, 2008, at 1:51 PM, Wolfgang N�dasi-Donner wrote: > >> If you include "it can be very confusing" into the list of possible >> answers, then the examples from "eigenclass.org" will show it... >> >> irb(main):001:0> -> a, b { a + b }.call(1,2) >> => 3 >> irb(main):002:0> c = 1; -> a, b; c { c = a + b }.call(1,2); c >> => 1 >> irb(main):003:0> c = 2; -> ;c { c = 1 }.call; c >> => 2 >> irb(main):004:0> c = 2; -> *d ; c { d }.call(1,2,3) >> => [1, 2, 3] >> irb(main):005:0> c = 2; -> ; c { c = 1 }.call; c >> => 2 >> >> Because the parantheses can be ommited, it can came closer to RegExes >> from the viewpoint of readability ;-) > > But all these now work with lambda, too: > > p(-> a, b { a + b }.call(1,2)) > # => 3 > p((lambda {|a, b| a + b }).call(1,2)) > # => 3 > > c = 1; -> a, b; c { c = a + b }.call(1,2); p c > # => 1 > c = 1; (lambda { |a, b; c| c = a + b }).call(1,2); p c > # => 1 > > c = 2; -> ;c { c = 1 }.call; p c > # => 2 > c = 2; (lambda { |;c| c = 1 }).call; p c > # => 2 > > > c = 2;p( -> *d ; c { d }.call(1,2,3)) > # => [1, 2, 3] > c = 2; p(lambda {|*d ; c| d }.call(1,2,3)) > # => [1, 2, 3] > > > I'm trying to work out if -> has any additional functionality over lambda. > My comment was more in the direction, that some words and examples like these may be very helpful for readers of the book, because it can be very confusing. I'm not against this construct. It is only a question of documentation. Wolfgang N�dasi-Donner