From: Jim Weirich Date: 2005-07-28T22:25:36+09:00 Subject: Re: What's so special about operators, built-in classes and modules? Austin Ziegler said: > When a module is mixed into a class, its references to instance > variables are bound to the instance of the class. > > module Foo > def baz > @baz ||= 0 > @baz += 1 > end > end > > class Bar > include Foo > def blat > @blat ||= 0 > @blat += 1 > end > end > > moof = Bar.new > moof.instance_variables # => [] > moof.blat; moof.instance_variables # => ["@blat"] > moof.baz; moof.instance_variables # => ["@blat", "@baz"] > > If we include classes, then we have to start caring about the origin > of instance variables. How would the above output be different if Bar were a class and we inherited from Bar? -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)