From: "David A. Black" Date: 2007-10-28T05:49:25+09:00 Subject: Re: .each do |foo, bar| what does bar do? Hi -- On Sun, 28 Oct 2007, 7stud -- wrote: > Brian Adkins wrote: >> On Oct 27, 7:05 am, "David A. Black" wrote: >>> i += 1 >>> end >>> self >>> end >>> end >> >> Or this: >> >> class Hash >> def each >> each_key {|key| yield key, self[key] } >> end >> end >> > > > That suffers the same problem as David Black's example. What problem did mine suffer from? > That example has raised a question of my own. Instead of having to > write: > > def each(&block) > orig_each(&block) > > why can't I relay the block to orig_each() without the second '&', like > this > > def each(&block) > orig_each(block) > > According to pickaxe2, p56, the '&' method converts the specified block > to a Proc object and assigns it to the parameter variable 'block'. Why > is the second call to '&' required? Because there's a difference between passing a Proc around as an object, and supplying a code block to a method. You can do both: meth(arg,&block) and arg can be a Proc object. So there has to be some way to tell the method what you're doing. David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Advancing With Rails, Edison, NJ, November 6-9 * Advancing With Rails, Berlin, Germany, November 19-22 * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details!