From: dblack@... Date: 2003-02-22T16:05:59+09:00 Subject: Re: Style question: using 'block_given?' Hi -- On Sat, 22 Feb 2003, Brian Candler wrote: > > This is the class instance variable police. Freeze! Keine Bewegung! > > > > ;-) > > It's a fair cop :-) I had a hard time getting my head round this one: > > - Class variables (@@data) are fine. > > - Instance variables in a module are fine: mix it into a class, and > instances of that class get those instance variables too > > - But @data as a class instance variable? You can't even refer to it, > except from within a class method. (Unlike a class variable, @@data, > which you can use within a normal instance method) It's probably most useful in an accessor. For example, if you want to keep a running tally of how many instances of a class have been created: class C class << self; protected; attr_accessor :instances; end @instances = 0 def initialize self.class.instances += 1 end end p C.instances # 0 C.new C.new p C.instances # 2 > It looks like something which the language has by accident more than by > design :-) Only if consistent, predictable design happens by accident, which I doubt :-) (See Gennady's explanation.) David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav