------art_43342_11956882.1190601323332
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

class MyArray
    def initialize
        @a  "hey", "whats", "up!"]
    end

    def each(&block)
        @a.each &block
    end
end
m  yArray.new
m.each{|el| p el} # "hey"
                                       "whats"
                                        "up!"

here we are simply reimplementing the each function of the array class, if
the need is to implement it functionally,
then we should use the "yield" explicitly.

On 9/24/07, Mike Steiner <mikejaysteiner / gmail.com> wrote:
>
> I have a simple class (this is just an example, so ignore any syntax or
> style errors):
>
> class MyArray
>     def initialize
>         @a  rray.new
>     end
>     def Push( item )
>         @a.push( item )
>     end
>     def GetArray
>         return @a
>     end
> end
>
> And I have this code:
>
> myarray  yArray.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
>



-- 
sur
"is a String object" is a String object
hacking over objects...
http://expressica.com

------art_43342_11956882.1190601323332--