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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:22:58+00:00 2026-05-12T10:22:58+00:00

If a class has been previously defined, how can I tell it to inherit

  • 0

If a class has been previously defined, how can I tell it to inherit from a class Parent?

For instance:

class Parent
  ..
end

class Klass
  ..
end

Now I want it to inherit from Parent.

I can’t re-open the class and set it because I will get a class mismatch error:

class Klass < Parent
  ..
end

Specifically, I am trying to find out how to set the class inheritance on a class I am creating through Object.const_set.

klass = Object.const_set('Klass', Class.new)

How can I tell Klass to inherit from class Parent?

  • 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-12T10:22:58+00:00Added an answer on May 12, 2026 at 10:22 am

    There is no way to change the superclass of an already existing class.

    To specifiy the superclass of a class you’re creating dynamically, you simply pass the superclass as an argument to Class.new.

    class Parent
    end
    klass = Class.new(Parent)
    klass.superclass #=> Parent
    

    Just as a side note: You’re not creating the class with const_set. You’re creating it with Class.new. You’re simply storing the created class in a constant with const_set. Once const_set is invoked, Class.new has already happened and the superclass cannot be changed anymore.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i check to see if a static class has been declared? ex
This has been driving me nuts for a week now. I have a class
Is it possible to know whether a Java class has been loaded, without attempting
Apparently in version 2 of JAXB - the validator class has been deprecated -
Sometime, when the Unit Test of a class has been done and method use
How to remove a class that has been appended to a div id? Earlier
A class has a property (and instance var) of type NSMutableArray with synthesized accessors
Previously a class which I'm now rebuilding had a member variable $settings which was
When using php exec you can pass it with a variable not previously defined
This issue has been previously reported, but I still have not been able to

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.