# Trying to grasp the difference between local variables and i

**URL:** <https://www.ruby-forum.com/t/trying-to-grasp-the-difference-between-local-variables-and-i/51034>\
**Category:** Rails\
**Created:** [December 24, 2005, 5:44am UTC](https://www.ruby-forum.com/t/trying-to-grasp-the-difference-between-local-variables-and-i/51034 "2005-12-24T05:44:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 24, 2005, 5:44am UTC](https://www.ruby-forum.com/t/trying-to-grasp-the-difference-between-local-variables-and-i/51034/1 "2005-12-24T05:44:04Z")

</div>

Hi:

Would it be fair to say (or completely out to lunch) that a local  
variable is local to a method and an instance variable is local to an  
object. Thus an instance variable is a sort of limited global  
variable or super-powered local variable. Its scope is larger than a  
local but smaller than a global. Or that it is a global within a  
limited domain (the object).

or is it a whole lot deeper than that?

I am told that the Hindus believe that God is near us always but a  
veil of delusion hides his glory from our eyes. I feel the same way  
about rails except that it is a veil of CONfusion that hides its  
glory from me. I believe its glory is there, waiting to be felt.

bruce

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 24, 2005, 5:56am UTC](https://www.ruby-forum.com/t/trying-to-grasp-the-difference-between-local-variables-and-i/51034/2 "2005-12-24T05:56:05Z")

</div>

On 12/23/05, Bruce B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi:
> 
> Would it be fair to say (or completely out to lunch) that a local  
> variable is local to a method and an instance variable is local to an  
> object. Thus an instance variable is a sort of limited global  
> variable or super-powered local variable. Its scope is larger than a  
> local but smaller than a global. Or that it is a global within a  
> limited domain (the object).
> 
> or is it a whole lot deeper than that?

In general terms, a local variable is in the scope of whatever is  
‘nearest’ to it.  
Usually that’s a method, but it doesn’t have to be (Procs are another  
possibility).

The only practical differences between the various kinds of variables  
are in where they are visible, and when they can be swept up by the  
garbage collector.

In other words, you had it right. Heh.

---

<div class="post-metadata">

**Author:** ![brucebalmer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@brucebalmer](https://www.ruby-forum.com/u/brucebalmer)\
**Post date:** [December 24, 2005, 6:44am UTC](https://www.ruby-forum.com/t/trying-to-grasp-the-difference-between-local-variables-and-i/51034/3 "2005-12-24T06:44:08Z")

</div>

Hi Bruce,  
Actually its deeper, and instance variable can also belong to a class  
because a class itself is an object.  
I would suggest you look at  
[http://groups.google.com/group/comp.lang.ruby/msg/f77ec15436916c69](http://groups.google.com/group/comp.lang.ruby/msg/f77ec15436916c69)  
and the ensuing thread.  
and this excellent noob examples by Ross B.  
[http://roscopeco.co.uk/code/noob/index.html](http://roscopeco.co.uk/code/noob/index.html)

Vivek
