From: Florian Frank Date: 2005-09-28T19:10:28+09:00 Subject: Re: Class and Iterator Design Question Jim Freeze wrote: > Ok, so you convinced me. Use #each. But, there still does not seem > to be a clear answer for an object having multiple containers. > Granted, there is precedence with things like #each_byte. But, > I wonder if it is better to use an argument to each. I think people should require 'enumerator' for this, it creates Kernel#enum_for, so you can create a Enumerable::Enumerator instance for every iterator: somethings = obj.enum_for(:each_something) Then you can iterate somethings.each do |something| # ... end and because Enumerator includes Enumerable, you can get an array as well by calling somethings_array = somethings.to_a without breaking encapsulation. This solves all your problems, and you only have to create an arbitrary named iterator method. I think enumerator should become part of Standard Ruby, because it's so damn useful.