From: dblack@... Date: 2003-10-02T21:46:24+09:00 Subject: Re: Instance- and class-variables (was Re: mixing in class methods) Hi -- On Thu, 2 Oct 2003, Gavin Sinclair wrote: > I initially tried to code my example like this: > > class Project > class << Project > attr_accessor :implemented_methods > end > > def implement(_method) > # some checking > yield > # some checking > Project.implemented_methods << _method > end > end > > Note in both examples, the idea is to be able to call > > Project.implemented_methods > > after calling Project#implement a number of times. However, the second > case (using a class instance variable instead of a class variable) did not > work. I think the array always came back empty. Now I may have done > something simple wrong, but I think I've demonstrated enough anyway. :) > Well, I hope so. Ummm, what array? :-) I think you'd need something like: class Project class << self attr_reader :implemented_methods def implemented_methods @method_list ||= [] end end def implement(method) Project.implemented_methods << method end end David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav