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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:37:34+00:00 2026-05-16T22:37:34+00:00

I come from C++ and JAVA, which with Scope there is either global or

  • 0

I come from C++ and JAVA, which with Scope there is either global or local.

I’m now learning ruby-on-rails and with ruby there is local, instance and global. I’ve never really heard of instance till now.

With or without rails, what is the understanding and usage of the instance variable?

Global = Variable across all objects share
Instance = Variable inside of the object
Local = Variable inside of the object

I think I’m getting instance and local kinda mixed together.

@ham
ham

These are two different variables right? Sometimes I get confused in Rails because they use stuff interchangably like @something and :something. Why is that?

Because I use the rails framework, all I understand the instance variable to be is something that is accessible by the view.

Can someone clarify these variables?

  • 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-16T22:37:34+00:00Added an answer on May 16, 2026 at 10:37 pm

    Instance variable in Ruby is like the one in Java, part of object state:

    class MyObject
      def set_x(x)
        @x = x
      end
    
      def get_x
        @x
      end
    end
    

    Equivalent Java code:

    class MyObject {
        private Object x;
    
        void setX(Object x) {
            this.x = x;
        }
    
        Object getX() {
            return x;
        }
    }
    

    And local variable is just a variable accessible only within this particular method:

    def doIt 
        x = 3;
        # x not accessible from outside of doIt
        puts x
    end
    
    void doIt() {
        int x = 3;
        // same in Java
        System.out.println(x);
    }
    

    edit
    What do you mean by object state?

    MyObject o = new MyObject();
    o.setX(3);
    // integer 3 is now stored in variable 'x' of object 'o'
    // I can return any time later and get that value back by 'o.getX()'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Its quite a while since I started learning Java EE (I come from Rails
I come from a Java background and I am learning Objective C. I am
I'm new to the rails environment and come from a java enterprise web application
I come from a Java background and I am now trying to study PHP
I come from a C, C++, and Java programming background, now getting my feet
I am learning Python at the moment, and I come from a Java/C++ and
I come from Java Background and so used to Debugging using Eclipse but have
I come from the Java world, so to me it's all object.foo() , but
I come from a Java background and am getting more into .NET, what are
I come from a Java background and have been using C# for the last

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.