Ryan Leavengood wrote:
> On 10/31/05, Trans wrote:
> >
> > Now what kind of use real might it have besides ObjectSpace? Simply
> > imagine any class that might have multipe each methods:
> >
> >   class House
> >     include EnumerableArgs
> >
> >     def each_bedroom ...
> >     def each_closet ...
> >     def each_room ...
> >     def each_hallway ...
> >
> >     def each(which=:room, &blk)
> >       send("each_#{which}", &blk)
> >     end
> >   end
> >
> >   h = House.new
> >   h.select(:bathroom) { |b| ... }
>
>
> I see your point, but:
>
> require 'enumerator'
>
> h = House.new
> h.enum_for(:each_bathroom).select {|b| ... }
>
> I *really* don't see how yours is much better. In fact, I'd argue the
> enumerator one is better because it is more explicit...anyone who
> knows how enumerator works can see what is happening. Only you, me and
> the people paying attention to this thread would understand what the
> EnumeratorArgs thing was doing.
>
> But I guess we will just have to agree to disagree, since we are both
> dragging this into one of those endless discussions threads that I
> dislike so much ;)
>
> Signing off,
> Ryan


IMHO, both are just circuitously avoiding:

class House

  def bathrooms
    @rooms.select {|r| r.typ == :bathroom}
  end
  def bedrooms ...
  def closets ...
  def hallways ...

end

h = House.new
h.bathrooms.each { |b| ... }


Yes, Enumerator is available in 1.9 without a /require/.
I think it'll stay because it works and there'll be no cause to
remove it.

It'll be an occasional source of amusement for me to mentally
rewrite any posted usage.  I envisage being able to backport
#enum_for and its ilk, in all but the most contrived examples,
instinctively.  :p

daz