Hacker News new | past | comments | ask | show | jobs | submit login

  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.



Usually you will have another level of indentation, so class methods shouldn't be that easy to mistake for instance methods.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: