T
Tony Arcieri
[Note: parts of this message were removed to make it a legal post.]
It seems there are 3 ways of defining class methods (at least in common
usage):
1) Defining a method on self:
def self.method
2) Opening up self and defining the methods directly:
class << self
def method
...
end
3) Placing class methods into a module, and extending a class with that:
module ClassMethods
def method
...
end
extend ClassMethods
--
Which of these do you use and which do you prefer? Do you use all three? Do
you think class << self is fugly and confusing?
I used to use class << self quite frequently and have been shifting to using
modules when dealing with a large number of class methods. I can't really
say I'm a huge fan.
It seems there are 3 ways of defining class methods (at least in common
usage):
1) Defining a method on self:
def self.method
2) Opening up self and defining the methods directly:
class << self
def method
...
end
3) Placing class methods into a module, and extending a class with that:
module ClassMethods
def method
...
end
extend ClassMethods
--
Which of these do you use and which do you prefer? Do you use all three? Do
you think class << self is fugly and confusing?
I used to use class << self quite frequently and have been shifting to using
modules when dealing with a large number of class methods. I can't really
say I'm a huge fan.