From: Jim Freeze Date: 2005-09-28T03:10:39+09:00 Subject: Re: Class and Iterator Design Question On 9/27/05, David A. Black wrote: > I think if you're using pod/peas as a container/elements example, then > you should accept that the container contains the elements :-) > > pod.each {|pea| ... } > > has enough pod/pea semantics to make it clear. In fact, this: > > pod.each_pea {|pea| ... } > > seems a bit redundant to me. (Unless there's something else that a > pod might iterate over, similar to String#each vs. String#each_byte. > Of course, lots of people wish that String#each did what > String#each_byte does :-) 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. Here are four methods that I can see as potential solutions: 1. obj.each(:container) { |element| ... } 2. obj.each_container { |element| ... } 3. obj.container.each { |element| ... } 4. obj.container; obj.each { |element| ... } No. (4) simply sets an internal state variable to indicate which container #each uses. Not pretty, and not thread safe, but permits Enumerable to be used. Do you have a preference for 1-4 or another solution? -- Jim Freeze