From: Michael Fellinger Date: 2010-08-22T03:35:02+09:00 Subject: Re: Adding *each* On Sun, Aug 22, 2010 at 2:45 AM, Ralph Shnelvar wrote: > I'm trying to wrap my head around how to do an "each" for objects of a class that I have created. > > Consider this contrived example >  class X >    def initialize >      @x = [10, 'a', 'c', 9, 8] >    end >  end > > In Ruby 1.8, what's the magic incantation so that I can do > >  x = X.new >  x.each {|y| puts y} > > I have read and reread Dave Thomas'*Programming Ruby 1.9* and ... well ...  I think I have to define *each* in class X and add some enumerable stuff ... but ... I just don't get it. class X include Enumerable def initialize @x = [10, 'a', 'c', 9, 8] end def each(&block) @x.each(&block) end end -- Michael Fellinger CTO, The Rubyists, LLC I check email a couple times daily; to reach me sooner, use: http://awayfind.com/manveru