From: Joel VanderWerf Date: 2005-01-25T05:35:35+09:00 Subject: Re: Complex Library Object/Class and its Interface Trans wrote: > Aredridel, > > Would that solve the access problem (i.e. being getting that info from > the class). I just tried: > > | class Parser::Token > | > | class << self > | > | def inherited(klass) > | klass.unit self.unit? > | klass.exclusive self.exclusive? > | klass.start &self.start > | klass.stop &self.stop > | end > | > | #... > > That solve the inheritence problem, it look like. But I'm jave > troubles. I'm starting to think that the problem is simply that I'm > trying to combine two different objects into one. This inheritance will not be updated when you change the value in the parent class. This seems to come up often enough that maybe ruby needs a built in way to inherit mutable and overridable variables in the class hierarchy. Class vars, class instance vars, and constants don't quite do this. You can do it with superhash: require 'superhash' class Token class_superhash :stuff class << self def start(*args) if args.size > 0 self.stuff[:start] = args[0] else self.stuff[:start] end end end end class Marker < Token start /marker start/ end class FooMarker < Marker end p Marker.start p FooMarker.start __END__ Output: /marker start/ /marker start/