class << self vs self.method z Ruby: co jest lepsze?
ToPrzewodnik po stylu Ruby mówi, że lepiej jest używaćself.method_name
zamiastclass method_name
. Ale dlaczego?
class TestClass
# bad
class << self
def first_method
# body omitted
end
def second_method_etc
# body omitted
end
end
# good
def self.first_method
# body omitted
end
def self.second_method_etc
# body omitted
end
end
Czy występują problemy z wydajnością?