From: gotoken@... (GOTO Kentaro) Date: 2001-01-16T20:56:45+09:00 Subject: [ruby-talk:9374] Re: attr_accessor in base class In message "[ruby-talk:9373] attr_accessor in base class" on 01/01/16, DaVinci writes: > I have a rpoblem with object orientation. Intention is to define > instances usable from all classes. For example: > > class Configuration > attr_reader :size > > def initialize(size) > @size = size > end > end > > class Foo > def initialize > puts @conf.size > end > end > > attr_reader :conf attr_reader is a private method of Class but you are using it in a Object cotext, i.e. the top-level self. > @conf = Configuration.new(100) And here, you are substituting to @conf which is an instance variable of the top-level self. So, @conf is never shared between the top-level self object and a Foo object; An instance variable is belong to a object. > Why I can not use attr_reader form base class?. Might I use a global > variable to define instance?. That is a way. You can solve this problem gloval variable if you really want to use that object everywhare. Otherwise I recommend a class varible @@conf of Foo. -- Gotoken P.S., Conrad, thanks for your kind explanation on Rocks :-)