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

  • SEARCH
  • Home
  • 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 6151951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:50:44+00:00 2026-05-23T19:50:44+00:00

When redefining a class method I want to be able to call super, just

  • 0

When redefining a class method I want to be able to call super, just as I would in a instance method.

For example, I have a class hi with a class method Hi.hi

class Hi
  def self.hi
    puts "hi"
  end
end

Hi.hi #=> "hi"

Now, Lets say i want to redefine self.hi

class Hi
  def self.hi
    super
    puts "Oh!"
  end
end

Hi.hi #=> NoMethodError: super: no superclass method `hi' for Hi:Class

Why doesn’t this work?

I know I can get the same functionality using alias (as below), it just seems rather unnecessary.

class Hi
  class << self
    def new_hi
      old_hi
      puts "Oh!"
    end
    alias :old_hi :hi
    alias :hi :new_hi 
  end
end

Hi.hi #=> "hi\n Oh!"

Is there a better way to do this?

  • 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-23T19:50:44+00:00Added an answer on May 23, 2026 at 7:50 pm

    Super works for child classes inherited from a parent class.

    In your case alias is the only way. Or you can use alias_method:

    alias_method :old_hi, :hi
    
    def self.hi
      old_hi
      puts "Oh!"
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have any good resources for refining my skills in developing class diagrams?
Has anyone done trimesh refining in the VCG library ? I would add that
I am redesigning a client's website so they will be able to edit the
I am redesigning a command line application and am looking for a way to
My company is redesigning our intranet site and decided to go with DotNetNuke as
We're in the process of redesigning the customer-facing section of our site in .NET
I've been tasked with redesigning part of a ms-sql database structure which currently involves
So, I am writing some sort of a statistics program (actually I am redesigning
Preface I'm learning about computer math by writing and refining my own BigInt library.
I need to read a HTML file and search for some tags in it.

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.