If you try this code:
class SomeClass p self end
you will get "SomeClass". This is because self refers to the SomeClass object (yes, clans are also objects in Ruby).
With self you can define class_method, i.e. method for the class object (although it is actually defined in the metaclass of the object ...):
class SomeClass def self.class_method puts "I'm a class method" end def instance_method puts "I'm an instance method" end end SomeClass.class_method
Learn more about the Ruby object model. Dave Thomas gave an excellent discussion on this subject - see @ Octopus-Paul Link recommended by you.
source share