From: Hemant Kumar Date: 2007-01-22T04:08:38+09:00 Subject: Re: module global variables On Mon, 2007-01-22 at 03:05 +0900, Gregory Brown wrote: > 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 > Well just a stolen idea from somewhere. But why not use module instance variables: module A @foo = "Bar" class << self; attr_accessor :foo; end end p A.foo PS : Sometimes I really need to think hard to differentiate between a class and a module. -- gnufied