From: Robert Klemme Date: 2005-04-17T19:49:39+09:00 Subject: Re: self "Trans" schrieb im Newsbeitrag news:1113672669.627263.226310@f14g2000cwb.googlegroups.com... > robert, > > i have one for you. tell me how to create a class whose subclasses DO > NOT inherit some particular state from. In other words I need: > > class Base > def self.state ; true ; end # or what have you > end > > class Derived < Base > end > > Derived.state #=> nil (was NOT inherited) > > how do i get something like that to work? Hey, that's an easy one: class Base class << self attr :state end instance_variable_set "@state", true end class Derived < Base end ?> Base.state => true >> Derived.state => nil :-) State is never inherited. The reason why your code didn't do what you wanted was that the implementation of the method was inherited. Btw, I would find something like this useful in the std lib: class Class def properties(*h) h = h[0] if h.size == 1 initial = {} h.each do |name, val| attr_accessor name initial[name]=val unless val.nil? end unless initial.empty? alias :new_plain :new class< 10 ) >> end => {:age=>10, :name=>"foo"} >> Foo.new.name => "foo" >> class Bar >> properties :name, :age >> end => [:name, :age] >> Bar.new.name => nil Cheers robert