3 ms·
Use def self.method to define singleton methods. ... # Also possible and convenient when you # have to define many singleton methods. class << self I w
by martingordon 15y ago
Use def self.method to define singleton methods.
...
# Also possible and convenient when you
# have to define many singleton methods.
class << self
I would argue against using "class << self" especially when you have many singleton methods. If the class is large enough, it's easy to miss the "class << self" and incorrectly read a class method as an instance method.
- arthurschreiber 15y agoUsually you will have another level of indentation, so class methods shouldn't be that easy to mistake for instance methods.