class << self idiom in Ruby

First, the class << foo syntax opens up foo‘s singleton class (eigenclass). This allows you to specialise the behaviour of methods called on that specific object. Now, to answer the question: class << self opens up self‘s singleton class, so that methods can be redefined for the current self object (which inside a class or module body is the class or module itself). Usually, … Read more