In this small article I would like to show different method of defining class Methods in ruby
First way is getting into class’s scope and defining a self method the as follows:
class HisClass def self.his_method; end end
Second way is to use the name of the class you want to define class method for as follows:
def HisClass.his_other_method; end
Third way is to make use of the eigenclass of which it stores the singleton methods. Note that the class methods are just Singleton methods that lives in class’s eigenclass. We can define it as follows:
class HisClass class << self def his_method; end end end
My preferable way is the first which has been embraced the Ruby on rails framework for long time. What is your preferable way for defining a class method and why?