From: Gregory Brown Date: 2007-01-22T03:05:38+09:00 Subject: Re: module global variables On 1/21/07, Gregory Brown wrote: > On 1/21/07, Stefano Zacchiroli wrote: > > On Mon, Jan 22, 2007 at 02:52:58AM +0900, Trans wrote: > > > > Am I using the wrong tool for my end? > > > Try a constant. > > > > Already tried. I can't stand the warning and I can't blame the compiler > > for outputting it: a constant would definitely be the wrong tool :) > > why do you need this in your module? Is it going to be mixed into > something or no? Something like this might work: >> module A >> def foo >> A.bar += 10 >> end >> module_function >> def bar=(other) >> @bar = other >> end >> def bar >> @bar >> end >> end => nil >> A.bar = 20 => 20 >> class B >> include A >> def apple >> foo >> end >> end => nil >> c = B.new => # >> c.apple => 30 >> c.apple => 40 >> c.apple => 50 >> class C >> include A >> def banana >> foo + 10 >> end >> end => nil >> d = C.new => # >> d.banana => 70 >> d.banana => 80 >> A.bar => 70