From: Sean O'Halpin Date: 2006-07-11T23:10:39+09:00 Subject: Re: Definition of methods: self I agree with Robert - avoid @@class_variables wherever possible. The problem is the way @@class_variables are looked up - they are shared within a class hierarchy. Also, class << LotteryDraw does not introduce a new class definition scope (even though you may think it looks like it should). The following examples demonstrate the way lookup for class variables works in the context you're using: class A @@a = 42 end # add a class variable to Object - without this, the next puts @@a would cause an error @@a = 24 class << A puts @@a # this refers to the toplevel Object @@a, not A's end class A puts @@a # this does refer to A's @@a end p @@a __END__ 24 42 24 (By the way, if you had run ruby with -w you would have got the warning: class variable access from toplevel singleton method ) Also, the order in which you define @@class_variables matters. Look at this example: @@a = 24 # add a class variable to Object class A @@a = 42 # because @@a already exists in the class hierarchy (A inherits from Object) # this assignment updates it end class << A puts @@a # there is only one @@a now end class A puts @@a end p @@a __END__ 42 42 42 My advice is steer clear of them! Regards, Sean