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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:07:45+00:00 2026-05-30T02:07:45+00:00

I have a several classes that inherit from a single class: class Bravo <<

  • 0

I have a several classes that inherit from a single class:

class Bravo << Alpha
class Charlie << Alpha

Alpha has some class level variables:

class Alpha 
  @@terms 

  def initialize 
    ...
    @@terms ||= load_terms 
  end 
end 

OK, all is fine so far. But I’d like to access the class level variables from the console for troubleshooting purposes. Is this possible? I’ve tried:

# inst is an instance of Bravo for example
inst.class.superclass:terms
inst.@@terms
inst.class.superclass[:terms]

Didn’t expect any of that to really work, just grabbing at straws since I couldn’t find any answer to the question. I’ve confirmed that the class variables are there via:

>> inst.class.superclass.class_variables
=> [:terms]

OK, I can see that they are there, but is there any way to directly access them via the rails console?

  • 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-30T02:07:45+00:00Added an answer on May 30, 2026 at 2:07 am

    You almost made it 🙂

    class Alpha
      @@terms = 'foo'
    end
    
    class Bravo < Alpha
    end
    
    b = Bravo.new
    puts b.class.class_variable_get '@@terms'
    # => foo
    

    It may look complicated, and it probably is so for a reason: to discourage people from messing with class’ internals (I don’t know if it’s true, I just made it up).

    If you need this on a regular basis, add an accessor for it!

    class Alpha
      @@terms = 'foo'
    
      def self.terms
        @@terms
      end
    end
    
    
    puts Alpha.terms
    # => foo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class CardStack . I have several classes that inherit from CardStack
Newbie Python question. I have a class that inherits from several classes, and some
This is for a web project so i have several classes that inherit from
I have a class BatchItem that inherits QObject , plus several classes that inherit
I have a class, which has a bunch of subclasses that inherit from it.
good morning, I have several objects that inherit from my father's class books and
I have several classes, that all derives from SuperClass. When the classes are created,
I have some methods that are used by several classes. My idea was to
I have a some code that gets passed a class derived from a certain
I have several classes that are basically interfaces to database rows. Since the class

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.