From: Ian Macdonald Date: 2002-04-26T11:48:28+09:00 Subject: how to check for unitialised class variable? Hi, Observe the following: irb(main):006:0> class Foo irb(main):007:1> def initialize irb(main):008:2> @@foo ||= true irb(main):009:2> end irb(main):010:1> end nil irb(main):011:0> bar = Foo.new NameError: uninitialized class variable @@foo in Foo from (irb):8:in `initialize' from (irb):11:in `new' from (irb):11 The ||= (only assign if nil) assignment operator must necessarily check for an existing value of @@foo and, if there isn't one, the above error ensues. How should one rewrite the above code? The objective is to avoid reassignment of @@foo, once it has been defined. Ian -- Ian Macdonald | The price one pays for pursuing any ian@caliban.org | profession, or calling, is an intimate | knowledge of its ugly side. -- James | Baldwin |