From: Sylvain Joyeux Date: 2005-08-07T20:57:59+09:00 Subject: Re: new block notation (was: Re: ruby-dev summary 26468-26661) > On the contrary, & un-blocks block: & has two uses: * it converts a block into a Proc object which is have a different behaviour than the Proc object created by lambda * it converts any Proc object (created by lambda, Proc.new or &) into the associated block On Sunday 07 August 2005 12:31, Trans wrote: > module Enumerable > def find > lamb = lambda { |x| return x if yield(x) } > self.each &lamb > end > end In you first example, the return is *inside* the lambaified block but & does an unlambda on it, so it works. "return" goes outside of the find function On Sunday 07 August 2005 13:26, Trans wrote: > module Enumerable > def find( &block ) > self.each { |x| return x if block.call(x) } > end > end In this example, return is inside a block, which is why it works too. In neither case you do use a lambda in the iteration construct: you use blocks, which is why it works. Another way to put it: let's image you would have an "each" that takes a proc instead of a block def find self.each Proc.new { |x| return x if yield(x) } end would work while def find self.each lambda { |x| return x if yield(x) } end does not You can check that by defining def each_proc(p) self.each { |x| p.call(x) } end -- Sylvain