From: Timothy Hunter Date: 2007-03-25T10:52:45+09:00 Subject: Re: class methods and instance variables in ActiveRecord::Base zig wrote: > On Mar 24, 3:56 pm, "Giles Bowkett" wrote: > > >> The answer to your question is that the class which inherits is opened >> up, and this method is defined within it. Not the instances -- the >> instances are untouched. This opens up the Class object itself. Then, >> obviously, it sets an instance variable. At that point, what it's >> doing is setting an instance variable of the Class object. >> >> > > OK, I think I'm getting there. > > Is an instance variable of the class object the same thing as a class > variable? > > For example, consider > > class A > @@var1 > end > > and > > class A > class << self > attr_reader :var1 > attr_writer :var1 > end > end > > In both cases I call that variable with A.var1. Are they the same? > > > A class variable is NOT the same as an instance variable of the class object. Have you tried "calling" @@var1 with A.var1? It doesn't work. The attr_reader and attr_writer methods create methods that operate on @var1. There is no method "var1" that operates on @@var1.