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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:49:37+00:00 2026-06-16T20:49:37+00:00

Possible Duplicate: Difference between class variables and class instance variables? While reading a Ruby

  • 0

Possible Duplicate:
Difference between class variables and class instance variables?

While reading a Ruby book, I seem to have missed the variables chapter. Now I can’t seem to understand the following things:

  1. What is an instance variable?
  2. What is a class instance variable?
  3. What is the difference between a variable, @instance_var and @class_instance_var?

I tried to read some posts in different blogs, but I still do not understand. Any help would be appreciated.

  • 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-06-16T20:49:38+00:00Added an answer on June 16, 2026 at 8:49 pm

    What is an instance variable?

    It’s a variable that has an idependant value that pertains to this instance of a class. For example, a Person class could have @name and @age as instance variables. All instance of Person have a name and age, but each instance will have a different value for those things.


    What is a class instance variable?

    This is a little wierd, but you have to realize that the Person class is itself an instance of Class. So it too can have instance variables. This is often used to configure a class. Like perhaps to add an API key to a class so that all instance can be created with that data.

    class PersonFetcher
    
      # class method can set class instance variables
      def self.set_api_key(key)
        @api_key = key
      end
    
      # instance method sets instance variables
      def set_name(name)
        @name = name
      end
    
    end
    

    What is the difference between a variable, @instance_var and @class_instance_var?

    How it persists.

    variable is local. It’s simply a reference to an object. Once no code or object has a reference to this value it is destroyed via garbage collection. It only persists if you keep using it.

    @instance_var persists on an instance. So long as the instance persists, the instance variables it has will as well. So long as the Person instance exists, that instance will have a @name.

    @class_instance_var persists on the class object (which remember is an instance of Class). So it will exist in the class object forever, since you can never really get rid of declared classes.

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

Sidebar

Related Questions

Possible Duplicate: Instance variables vs. class variables in Python What is the difference between
Possible Duplicate: Difference between Color.red and Color.RED I have seen that the Java class
Possible Duplicate: Difference between class property mVar and instance variable self.mVar I am new
Possible Duplicate: Python: Difference between class and instance attributes I'm trying to get my
Possible Duplicate: Difference between object and instance I have couple of questions: Every instance
Possible Duplicate: What’s the difference between calling MyClass.class and MyClass.getClass() Wanting to have a
Possible Duplicate: Difference between self.ivar and ivar? Let's say I have the following class
Possible Duplicate: What is the difference between a pseudo-class and a pseudo-element in CSS?
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading
Possible Duplicate: difference between string object and string literal Let's say I have two

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.