-
Book Overview & Buying
-
Table Of Contents
Polished Ruby Programming - Second Edition
By :
Ruby programmers often refer to methods you can call on classes as class methods. However, Ruby does not have class methods as a separate concept. Ruby only has instance methods. Every method that you would think of as a class method or a module method is an instance method of the class or module's singleton class, or an instance method in a module included in or prepended to the singleton class. That doesn't mean that you should stop using the terms class method or module method, but you should understand that these methods are not special or different than normal methods.
You will generally see class methods defined in one of four ways. The most common way is to use self in front of the method:
class Foo
def self.bar = :baz
end
This makes it obvious that the method being defined is a singleton method, because any method definition in Ruby that uses the def expression.name format defines a singleton method...
Change the font size
Change margin width
Change background colour