class One class << self def set name, value = 0 @values ||= {} @values[name] = value end def get name @values[name] end end def to_s self.class.get(:x) end end class Two < One set :x, 1 end class Three < One set :x, 2 end o1 = Two.new o2 = Three.new puts "#{o1.to_s} | #{o2.to_s}"