DEV Community

chenge
chenge

Posted on

1 2

Understanding the Eigenclass in less than 5 minutes

Today I read Understanding the Eigenclass in less than 5 minutes. It explained clearly.

class Greeting
  def self.hello
    'hello world!'
  end

  def self.eigenclass
    class << self
      self
    end
  end
end

Greeting.eigenclass      # => #<Class:Greeting>
Greeting.eigenclass.name # => nil

Greeting.singleton_methods                  # => [:hello, :eigenclass]
Greeting.eigenclass.instance_methods(false) # => [:hello, :eigenclass]
class << self

This weird syntax means the eigenclass context.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay