Описание тега eigenclass

In Ruby, an Eigenclass, also called a Singleton Class, is where methods defined on a specific object are actually stored. In the inheritance chain, it sits between an object and its class.

An Eigenclass, also known as a "Singleton Class," is an invisible class created by the Ruby interpreter when you define methods on a specific object. For example:

class American
  def greet
    puts "Nice to meet you!"
  end
end

lucy = American.new

# This method actually gets defined on 
# lucy's eigenclass
def lucy.greet       
  puts "Hi, I'm Lucy."
  # "super" tries to call a method by
  # the same name as this one, further
  # up the inheritance chain. In this
  # case, it will find American#greet
  super
end

lucy.greet 
# "Hi, I'm Lucy."
# "Nice to meet you!"

Further reading: