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 Hodel, post: 4503433"] instance variables are always stored in the instance self. class variables are shared between a class, its instances, its subclasses and its subclass instances. Consider: class A @@a_1 = :one def initialize @@a_2 = :two end end A.new class B < A p @@a_1, @@a_2 @@b_1 = :three def initialize @@b_2 = :four end def print p @@a_1, @@a_2, @@b_1, @@b_2 end end class A x = @@b_1 rescue 'not found' y = @@b_2 rescue 'not found' p x, y end B.new.print [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
question about class variables and instance variables
Top