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 6342123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:10:39+00:00 2026-05-24T20:10:39+00:00

class A def self.a puts self: #{self}; superclass: #{superclass} end end class B <

  • 0
class A
  def self.a
    puts "self: #{self}; superclass: #{superclass}"
  end
end

class B < A
  class << self; undef_method(:a); end  # I'm not allowed to use B.a
  def self.b
    # here I want to call A.a with B as self.
  end
end  

A.a  #=> self: A; superclass: Object
B.b  #=> self: B; superclass: A (expected)

I don’t want an alias_method solution. I’m looking for something like this.

UPDATE

The solution doesn’t need to be any similar to the link above; it’s only a suggestion. For example, I tried to do:

class B < A
  def self.b
    instance_eval(&A.method(:a).to_proc)
  end
end

but this way I get an weird ArgumentError on Ruby 1.8.7.

  • 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-24T20:10:39+00:00Added an answer on May 24, 2026 at 8:10 pm

    Only solution here is to use B.a.

    class B < A
      def self.b
        a #=> self: B; superclass: A
      end
    end  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Foo def self.bar puts foobar end def bar self.class.bar end end I want
eg: class Base def self.inherited(subclass) puts New subclass: #{subclass} path_of_subclass = ???? end end
In ruby you can do this: class A def self.a 'A.a' end end puts
I have the following code: #!/usr/bin/ruby class Person def self.speak p = self.new puts
my ruby (on rails) class looks like: class Foo def self.method1 someAction end def
Following code works def lab Proc.new { return foo1 }.call return foo2 end puts
I'm trying to figure why this code: class BaseClass end module Extensions def self.included(base)
Here is what my code looks like: module A def foo puts A end
I want to call a protected superclass class method from an instance method in
class A private def initialize puts wtf? end end A.new #still works and calls

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.