I’m learning ruby and ROR at the same time and noticed one thing in someone else’s code. Sometimes I see methods being defined in these two apparently slightly different ways:
class SomeClass < SomeInheritance::Base
def self.myMethod
end
def myOtherMethod
end
end
Does it make any difference? I mean, does the use of self in a method definition affects the way the method works somehow? Any enlightenment is welcome.
def self.method_namewill define a class method rather than an instance method – as willclass << self; def foo; end; endA good post on the topic is this post from Yehuda Katz
for example: