# Re: newbie doesn't understand why's example

**URL:** <https://www.ruby-forum.com/t/re-newbie-doesnt-understand-whys-example/96233>\
**Category:** Ruby\
**Created:** [June 27, 2006, 3:57pm UTC](https://www.ruby-forum.com/t/re-newbie-doesnt-understand-whys-example/96233 "2006-06-27T15:57:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kivle](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@kivle](https://www.ruby-forum.com/u/kivle)\
**Post date:** [June 27, 2006, 3:57pm UTC](https://www.ruby-forum.com/t/re-newbie-doesnt-understand-whys-example/96233/1 "2006-06-27T15:57:50Z")

</div>

This one got me a bit also at first, but it’s like others have said.  
Maybe this will make it clearer:

class Array

# Build a string from this array, formatting each entry

# then joining them together.

def join( sep = $, format = “%s” )  
collect do |item|  
sprintf( format, item )  
end.join( sep )\<\<\<\<big confusing stmt  
end  
end

This would create the endless loop that you expected. Notice that  
instead of creating a subclass called ArrayMine that extends Array, I’ve  
instead redefined the join method of the Array-class itself. Since  
Array.collect returns an Array, Array.join would now cause an endless  
recursive loop creating an infinitely long array.

The gotcha is basically that ArrayMine.collect returns an Array, and not  
an ArrayMine.

Regards,  
Helge E.
