From: David Alan Black Date: 2002-01-14T12:04:00+09:00 Subject: Re: Small Methods - a ramble Hi -- On Mon, 14 Jan 2002, Ron Jeffries wrote: > On Sun, 13 Jan 2002 23:49:36 GMT, David Alan Black wrote: > > > > > > > > >Are you sure you want to use 'each' as the iterator variable name? > >Memories of naming methods 'test' rear their ugly heads.... > > > > [ [1,2], [3,4] ].each {|each| each.each {|each| p each}} > > Yes, well, I wouldn't do that, and especially wouldn't use each in > two nested loops ... I didn't think you would (!) -- I was just curious whether that example would actually work (as opposed to the eaches stepping on, ummm, each other's toes). [...] > Smalltalkers use 'each' for that variable, so that's why we do > it. If the variable's type isn't obvious we might call it > 'eachFilename" or the like. > > I don't read enough Ruby code to know if there's a standard thing > naming convention for the iteration variable. Is there? I think there's a semi-convention to make iterator variable names, on average, shorter than the surrounding variables -- so you might get something like: filenames.each do |fn| ... or array_of_arrays.each do |ary| ... and then sometimes the thing itself guides one: some_array.each_index do |i| ... or some_hash.each do |k,v| ... (although that last one turns up more in demo snippets than real programs). David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav