From: ts Date: 2001-09-03T21:36:48+09:00 Subject: [ruby-talk:20769] Re: Dynamic generation of class variables? >>>>> "R" == Renald Buter writes: R> NEXT to that, I would like to enter 'max' and 'min' as keys into a class R> variable '@@properties' to allow me to inspect which properties a R> particular instance has. use the class variable @properties If I take your example in [ruby-talk:20614] this give something like this pigeon% cat b.rb #!/usr/bin/ruby class A def self.property( token, value ) unless respond_to?(:properties) @properties = {} class_eval <<-EOD def self.properties @properties end EOD end @properties[token.to_s] = value class_eval <<-EOD def #{token} @#{token} ? @#{token} : @#{token} = self.class.properties["#{token}"] end def #{token}=( value ) @#{token} = value end EOD end end class B < A property :a, [1, 2] property :b, "foo" end class C < A property :c, 10 end ### Testing ### b1 = B.new b2 = B.new b1.b = 2 c = C.new p B.properties B.properties.each do |p, h| puts "original value #{h} b1=#{b1.method(p).call},b2=#{b2.method(p).call}" end p C.properties puts c.c pigeon% pigeon% b.rb {"a"=>[1, 2], "b"=>"foo"} original value 12 b1=12,b2=12 original value foo b1=2,b2=foo {"c"=>10} 10 pigeon% Guy Decoux