------art_3162_8519516.1151419646661
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On 6/27/06, ts <decoux / moulon.inra.fr> wrote:
>
> >>>>> "d" dave rose <bitdoger2 / yahoo.com> writes:
>
> d> Please give an example where the arraymine (or any other example) join
> d> WOULD recursively recall itself so that i can see the difference....
>
> Well, here a recursive function
>
> moulon% cat b.rb
> #!/usr/bin/ruby
> class ArrayMine < Array
>    # Build a string from this array, formatting each entry
>    # then joining them together.
>    def join( sep  ,, format  %s" )
>       x  ollect {|item| sprintf( format, item ) }
>       y  rrayMine.new(x)
>       y.join(sep)
>    end
> end
>
> p ArrayMine[1,2].join
> moulon%
>
> First it create an Array `x'
> Create an object ArrayMine `y'
> Then call #join for `y' (i.e. ArrayMine#join)
>
> moulon% ./b.rb
> ./b.rb:6:in `join': stack level too deep (SystemStackError)
>         from ./b.rb:8:in `join'
>         from ./b.rb:12
> moulon%
>
> The original version is
>
>
> moulon% cat b.rb
> #!/usr/bin/ruby
> class ArrayMine < Array
>    # Build a string from this array, formatting each entry
>    # then joining them together.
>    def join( sep  ,, format  %s" )
>       x  ollect {|item| sprintf( format, item ) }
>       x.join(sep)
>    end
> end
>
> p ArrayMine[1,2].join
> moulon%
>
> First it create an Array `x'
> Then call #join for `x' (i.e. Array#join)
>
> moulon% ./b.rb
> "12"
> moulon%
>
>
>
> Guy Decoux
>
>
>
>
>
The stumbling block here seems to be that x is an instance of class Array,
and not your new class, ArrayMine. To make it infinitely recursive, x would
have to be of type ArrayMine. To do this you would have to override the
collect method to return an ArrayMine instead of an Array.

-- 
--- Shane Emmons <semmons99 / gmail.com>

------art_3162_8519516.1151419646661--