From: Eric Mahurin Date: 2005-09-28T03:14:48+09:00 Subject: Re: Class and Iterator Design Question --- Jim Freeze wrote: > On 9/27/05, David A. Black wrote: > > Why not just call that #each? (And, as others have said, > possibly > > include Enumerable, though only if you need the other > Enumerable > > stuff). > > Good question. > > 1) Pod.each { |pea| ... }. There is no indication what each > will yield. > 2) In some cases, there are multiple things that can be > iterated through. > Maybe a better example: > > Car.new.each_wheel { |wheel| ... } > Car.new.each_headlight { |light| ... } > > Which directs me to do something like: > Car.new.wheels.each ... > Car.new.headlights.each ... > > which is back to the un-encapsulation that has been > previously mentioned. I still think the second way is just fine if you just say in the docs that #wheels and #headlights returns an Enumerable. Or if you really wanted to make sure there is no abuse, just make #wheels and #headlights return an Enumerator (naming @wheels.each and @headlights.each as the each methods). Or if you wanted to be v1.9-like make #each_wheel and #each_headlight return an Enumerator when no block is supplied. __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com