From: zdennis Date: 2006-04-08T01:56:45+09:00 Subject: Re: Simple Question About Deleting Instances Nathan Olberding wrote: > zdennis wrote: >>> def method_name() >>> ... >>> end >> This is an instance method. It works on the instance of Report. >> >>> And my variables are all defined as: >>> >>> @@var = ... >> This is a class variable. All Reports will share this variable. You >> probably want to make it an instance variable with one @ symbols. >> >> @var = ... > > I replaced all instances of "@@" with "@" in my script since I don't > need any class variables. Now, Ruby generates errors telling me that all > of these variables are unknown when referenced from instance methods. Can you post code along with your questions ? It makes it so much easier to help. > > Do I need to make any special kinds of accessors or anything? > > And on that note, how do I do something like attr_reader :@@var? Ruby > doesn't seem to know what to do when I put those @s there. 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 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. Zach