2006/6/4, Sy Ali <sy1234 / gmail.com>:
> On 6/4/06, Robert Klemme <shortcutter / googlemail.com> wrote:
> > Your problem here is that you call Kernel.split which is private
>
> I think I understand.  I'm not entirely sure why the same block of
> code will use split in one way verses another way (kernel vs string)
> depending entirely upon the array that its working on.. but things
> have worked out in the end.

You're seeing basic object orientation at work here: a method is
always invoked on an object and it depends on the type of the object
which behavior is exposed. The only special thing about Kernel.split
is that it's usually invoked without an explicit receiver, which means
"self" is the receiver.  That's why I presented the example calls from
my IRB session that show what class the different methods were defined
on.  I don't know your background so it's probably a bit difficult to
grasp in the beginning. But then again, Ruby is one of the better
languages to learn OO with because it minimizes on the number of
exceptions: in Ruby everything is an object and there is no
distinction between POD's and objects like in Java for example.

> > Solutions have been suggested already.  Here's another one that avoids
> > the use of flatten because that is less efficient:
>
> Thank you.. that obsoleted a wierd block of code I whipped up.

#inject frequently does. :-))

Kind regards

robert


-- 
Have a look: http://www.flickr.com/photos/fussel-foto/