Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
question about class variables and instance variables
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Eric D., post: 4503428"] Hello, I've some difficolties with instance variables and classe variables With : class A def foo @foo end def bar @@bar end end a = A.new --------- ------------ ------------ | | | | | | | a |--(instance_of)->-| A |--(instance_of)->-| Class | | | | | | | --------- ------------ ------------ a is an instance of A which itself is an instance of Class @foo is an instance variable, so it is stored in box "a" @@bar is a class variable, so it is stored in box "A" if I do something like the following : class A def A.strange @strange end end Where is stored my @strange ? I had the hypothesis that @strange in the "A" context was equivalent to @@strange in the "a" context but the following code prove me to be wrong : class A def A.strange @strange end def strange=( val ) @@strange = val end end a = A.new a.strange= 2 p A.strange # output is nil, not 2 Could someone explain me where to place this @strange ? in which box could I store it ? Thanks in advance [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
question about class variables and instance variables
Top