Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 576429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:02:46+00:00 2026-05-13T14:02:46+00:00

In Ruby, we could use super within singleton method to call the corresponding super

  • 0

In Ruby, we could use super within singleton method to call the corresponding super class’s singleton method, like the following code shows.

class Base
  def self.class_method
    puts "Base class method"
  end
end

class Derived < Base
  def self.class_method
    puts "Derived class method"
    super
  end
end

Derived.class_method
# Derived class method
# Base class method

However, I don’t seem quite get how that call to super within Derived.class_method could reach Base.class_method. I’d assume that class_method is defined on their metaclass, does that mean their metaclass has parent/child relationship? (I can’t quite confirm that by experiments)

Update: I’m asking this question because I remembered seeing somewhere there’s some kind of relationship bettwen base and derived class’ metaclass (but I can’t find it any more). In addition to know how actually super works, I’d also like to confirm whether the two metaclasses are totally separate or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:02:46+00:00Added an answer on May 13, 2026 at 2:02 pm

    There are four class objects in play here:

    <Class>---class---><Class>
    Base               #Base
       ^                  ^
       |                  |
       |                  |
     super              super
       |                  |
       |                  |
    <Class>            <Class>
    Derived---class--->#Derived
    

    Nomenclature:

    • <…> is the class of each object.
    • The name of the class is on the second line.
    • If the name starts with #, it’s the eigenclass (aka singleton class).
    • super points to a class’s superclass
    • class points to the class’s class.

    When you call Derived.class_method, Ruby follows the "right one and then up" rule: First go to the object’s class, then follow the superclass chain up, stopping when the method is found:

    • The receiver of the "class_method" call is Derived. So follow the chain right to Derived’s class object, which is its eigenclass (#Derived).
    • Derived does not define the method, so Ruby follows the chain up the chain to #Derived’s superclass, which is #Base.

    • The method is found there, so Ruby dispatches the message to #Base.class_method

    You don’t think I knew all this stuff off the top of my head, did you? Here’s where my brain got all this meta juju: Metaprogramming Ruby.

    Part 2. How to make an "eigenclass" (aka "singleton class") come out of hiding

    class Object
      def eigenclass
        class << self
          self
        end
      end
    end
    

    This method will return the eigenclass of any object. Now, what about classes? Those are objects, too.

    p Derived.eigenclass               # => #<Class:Derived>
    p Derived.eigenclass.superclass    # => #<Class:Base>
    p Base.eigenclass                  # => #<Class:Base>
    

    Note: Above is from Ruby1.9. When run under Ruby 1.8, you get a surprise:

    p Derived.eigenclass.superclass    # => #<Class:Class>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 407k
  • Answers 407k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer 1] don't write ApplicationController.current_account Just current_account 2] in your application_controller… May 15, 2026 at 6:37 am
  • Editorial Team
    Editorial Team added an answer If you want to use code behind then you can… May 15, 2026 at 6:37 am
  • Editorial Team
    Editorial Team added an answer You'll need the experimental HTML 5 Websockets see slides for… May 15, 2026 at 6:37 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.