Forum: Ruby on Rails Trying to grasp the difference between local variables and i

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2dd904ec5981c31e7bb7a5743a53caf8?d=identicon&s=25 Bruce Balmer (brucebalmer)
on 2005-12-24 05:44
(Received via mailing list)
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
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2005-12-24 05:56
(Received via mailing list)
On 12/23/05, Bruce Balmer <brucebalmer@mac.com> 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.
6828ffc79486cd2442714bf32286a910?d=identicon&s=25 Vivek Krishna (Guest)
on 2005-12-24 06:44
(Received via mailing list)
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/...
and the ensuing thread.
and this excellent noob examples  by Ross B.
http://roscopeco.co.uk/code/noob/index.html

Vivek
This topic is locked and can not be replied to.