From: ara.t.howard@... Date: 2006-02-07T08:01:04+09:00 Subject: Re: Method Definitions: &block vs. yield() On Tue, 7 Feb 2006, James H. wrote: > Suppose I had two methods: > > # First method > def my_first_method(b) > yield b > end > > # Second method > def my_second_method(&block) > block.call > end > > I know that the block in the 2nd example is converted to a Proc object, > but a Proc object (to my newb eyes) doesn't seem to hold any advantages > that might make me want to use the latter method. > > I was wondering if there are specific advantages to using the &block > convention or yield()ing a block? Is it merely a matter of preference > and or convention? > > James harp:~ > cat a.rb class C def foo(&b) bar &b end def bar() yield end end C::new.foo{ p 42 } harp:~ > ruby a.rb 42 -a -- happiness is not something ready-made. it comes from your own actions. - h.h. the 14th dali lama