From: "David A. Black" Date: 2007-10-28T05:30:07+09:00 Subject: Re: .each do |foo, bar| what does bar do? Hi -- On Sun, 28 Oct 2007, Brian Adkins wrote: > On Oct 27, 7:05 am, "David A. Black" wrote: >> If you were going to write Hash#each in Ruby, without recourse to >> #each, you could write it like this: >> >> class Hash >> def each >> keys = self.keys # make a 'keys' local variable >> i = 0 >> until i == keys.size >> key = keys[i] >> yield(key, self[key]) >> i += 1 >> end >> self >> end >> end > > Or this: > > class Hash > def each > each_key {|key| yield key, self[key] } > end > end > > I know, you meant w/o recourse to each* :) Yes -- I don't think each_key uses each but it's definitely out of bounds for my example :-) Mainly, of course, I wanted to "explode" the whole thing so that the underlying logic was brought to the surface. 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!