From: Jim Driscoll Date: 2004-01-25T20:44:06+09:00 Subject: Re: Constant inheritance On 25 Jan 2004, at 11:31, David Heinemeier Hansson wrote: >> You could just use a class variable (e.g. @@x) instead, the downside >> being that it *would* be variable rather than constant. > > Right. The problem is that this really is a constant. The previous > example was a bit abstract. This should be more telling of my > intentions: > > ...but perhaps you're right. A class variable would probably suffice. > Okay, try this then (referring explicitly to the current namespace): irb(main):001:0> class A irb(main):002:1> X=2 irb(main):003:1> def X irb(main):004:2> self.class.const_get :X irb(main):005:2> end irb(main):006:1> end => nil irb(main):007:0> class B < A irb(main):008:1> end => nil irb(main):009:0> class C < A irb(main):010:1> X=3 irb(main):011:1> end => 3 irb(main):012:0> A.new.X => 2 irb(main):013:0> C.new.X => 3 irb(main):014:0> B.new.X => 2 irb(main):015:0> Jim