What confuses you is the difference between class and instance methods.
Class methods do not have an explicit receiver, and thus do not have self to access other fields. They just ... are.
Typically, instance methods are used to query or manipulate attributes of a given object, while class methods are helper or factory methods that provide some functions related to or especially useful for a particular class, but it does not depend on real live instances (objects ) of this class.
Not sure about Ruby, but Java has (for example) an entire Math class that only contains instances that look like sin() , max() , exp() , etc.: "Math" does not exist, object, this just methods that embody mathematical algorithms. Not a good example, because in Ruby, these methods are probably embedded directly in number classes as instance methods.
The case you mentioned is a bit confusing because the Array () and Kernel Array() methods are actually different methods that do similar things. Both are class methods.
Array() takes a list of arguments and creates and returns an array containing them.
Kernel.Array() takes a single argument of type "array-able", such as a sequence, and takes the values ββreturned by this argument and builds an array from them.
UPDATE
The shift was perhaps justified; I apologize for the fact that you are engaged in a subject outside my competence. I think I will delete this answer soon.
@ Chuck: I sincerely hope that the official documentation in the language / library will offer some meaningful clues as to how this works. This is what I consulted when answering this question.
rdoc for Kernel.Array() :
Returns arg as an array. It tries to call arg.to_ary first, then arg.to_a. If both fail, creates one array of elements containing arg (if arg is not equal to zero).
for Array.() :
Returns a new array filled with these objects.
I donβt know about you, but I think that if the documents change so much, either they speak of separate methods, or the documentation is a train wreck.
@ freeknight:
But everything in the ruby ββis an object of some kind, even classes and modules. And Kernel.Array is actually a method call for a specific object - a kernel object.
Yes, under the covers it looks like Java too. But the Array() method does nothing with Kernel, no more than Array() does anything with an object of the Array class, so this is really just a semantic pun. This is an instance method because you could disconnect it from the IPSocket class if you were crazy enough and it would work the same anyway.