From: Mike Steiner Date: 2007-09-24T11:14:11+09:00 Subject: how to add an iterator to a class? ------=_Part_32644_20799074.1190600051525 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline I have a simple class (this is just an example, so ignore any syntax or style errors): class MyArray def initialize @a = Array.new end def Push( item ) @a.push( item ) end def GetArray return @a end end And I have this code: myarray = MyArray.new myarray.Push( 1 ) myarray.Push( 2 ) myarray.GetArray.each do | i | puts i end So my question is: How do I replace GetArray with something more elegant, that gives MyArray a method named .each that I can call directly? Michael Steiner ------=_Part_32644_20799074.1190600051525--