From: Nathan Olberding Date: 2006-04-08T02:08:22+09:00 Subject: Re: Simple Question About Deleting Instances zdennis wrote: > Can you post code along with your questions ? It makes it so much easier > to help. class A @@a = 1 @b = 2 def say_stuff() puts @@a # Works puts @b # Doesn't work end end > When using attr_reader, attr_writer, attr_accessor you dont need to > include the @ symbols. > > class A > attr_accessor :var # this will create an instance variable @var > # plus the get/set methods for var on an instance > # of A > > class << self > attr_accessor :foo # this will create a class method var for you > # plus the get/set methods for var on the class > # A. The var will be created as an instance > #variable @var on the class A > end > end > > a = A.new > a.var = 5 > puts a.var #outputs 5 > > b = A.new > b.var = 10 > puts b.var #outputs 10 > > A.foo = 100 > puts A.foo #outputs 100 That seems way more convoluted than just: class A @@var = "" attr_accessor :@@var end Class << self creates class variables by the same name as instance variables? So you'd have both @@var and @var? Is there a specific reason for this? It seems HIGHLY unpredictable. > Please do read the Chris Pines Learn To Program from my last post. It > seems you are guessing at what goes where and you need little a > guidance, Chris Pines Learn to Program will help you get started in the > right direction. I'll at least give it a glance at lunch time. Sounds promising. Thanks! -- Posted via http://www.ruby-forum.com/.