From: Robert Klemme Date: 2004-02-27T00:59:58+09:00 Subject: Re: Why don't $global and @instance variables need *initialization*? "David Garamond" schrieb im Newsbeitrag news:403E125E.1020506@zara.6.isreserved.com... > ts wrote: > >>>>>>"D" == David Garamond writes: > > D> Btw, what do people think of adding the following system hooks in Ruby: > > What are you trying to solve ? > > Making Ruby raise NameError when an uninitialized global or instance > variable is accessed (just like when a new local variable is mentioned > without being assigned first). Why do you need that? What about lazy init? class Foo def bar;@bar||={};end end f = Foo.new f.bar["hello"] = "world" .... or the common ad hoc init idiom? class Bar def add(name) (@names||=[]) << name end end b = Bar.new b.add "hello" Regards robert