From: Trans Date: 2008-12-03T05:04:18+09:00 Subject: Re: Class atrr_accessor On Dec 2, 2:16 pm, Oliver Saunders wrote: > Why does this not work? An ideology? > >> class Foo > >>   self.class.attr_accessor :baz > >>   end > > TypeError: Foo is not a class >         from (irb):19 class Module public :attr_accessor end All fixed. > I understand that the class << self idiom can be used to work around > this problem but I would like to understand why the above triggers such > an error and what is meant by it. Well, I think the idea is that you shouldn't be changing a class' interface from the "outside" ie. so willy-nilly. So you are required to go "inside" to get the job done. Sort of a caution barrier. But it does suck that this requires a second layer, eg. class << self, to get there. I have tried a private #meta method in the past. class Foo meta.attr_accessor :baz end which works, though I'm not sure the term "meta" feels quite right. I've avoided ever using it though because I know others would look at it and think "what?". T.