From: Patrick Fernie Date: 2007-02-06T00:29:42+09:00 Subject: Re: Proc vs lambda vs proc I found the following: http://innig.net/software/ruby/closures-in-ruby.rb to be an interesting read on the different flavors of closures in ruby; I think it takes into account some of the 1.9 changes, but it may be slightly outdated... -P On 2/5/07, Minkoo Seo wrote: > On Feb 5, 4:37 am, Jim Weirich wrote: > > Minkoo Seo wrote: > > > [...] > > > The secondis that lambda returns as we expect, i.e., it > > > returns value, while Proc.new does not. > > > > lambda and Proc.new do handle the return statement in different ways. > > Return in lambda returns from the lambda, treating the lambda as an > > anonymous function. > > > > Return in Proc.new returns from the enclosing method, treating the block > > as an inline piece of code. > > > > The Proc.new behavior is useful where the block is simply a bit the > > algorithm. For example: > > > > I guess the following block (do |item| ... end) > > > def member?(target, list) > > list.each do |item| > > return true if target == item > > end > > false > > end > > The explicit return should return from the member? method, not just from > > the loop. > > > > -- Jim Weirich > > is block and not a proc. > > AFAIK, block is not converted to proc unless the block is captured by > parameter like &blk. Am I wrong? > > Sincerely, > Minkoo Seo > > >