What I want to do is have some "meta" information about an object's members. So for example if an object has two members: ht and wt, I want to associated with them the names to display if I have an object display module. I would like to use the following code to use this capability. def dump_objects(objects) objects.each do |object| object.userVars.each { |member| print "#{object.userHash[member][name]}: #{object.send(get + "member").to_s}\n" print "\n" end where dump_objects([Contact.new("Joe", "Schmo"), Address.new("1212 Penny Lane", "London", "UK", "4A3B2A"), ...]) would display First Name: Joe Last Name: Schmo Street: 1212 Penny Lane City: London Country: UK Postal Code: 4A3B2A Then I would like to define the Contact and Address objects as such: def Contact uservar :first_name, { Name => "First Name" } uservar :last_name, { Name => "First Name" } end def Address uservar :street, { Name => "Street" } uservar :city, { Name => "City" } uservar :country, { Name => "Country" } uservar :postal_code, { Name => "Postal Code" } end I have done this kind of stuff in C code that I have written to drive UI's. What I need is this information stored in a class variable for each individual class that I define (ie. Contact, or Address). In my first attempt at it, I ended up with one class variable that was in the superclass of all the other classes I defined. So Contact would have a class variable @@userVars and Address would have a class variable @@userVars. Can this be done as above? Thinking about it, I could just put a line like the following in every classes initialize routine: def initialize @@userVars = { :street => { Name => "Street" }, :city => { Name => "City" }, .. .. } end I just thought I would like to use the ability to do something like attr_reader, etc to implement this capability. Sorry this was so long winded. Steve Tuckner -----Original Message----- From: matz / zetabits.com [mailto:matz / zetabits.com] Sent: Saturday, June 16, 2001 8:57 AM To: ruby-talk / ruby-lang.org Subject: [ruby-talk:16538] Re: Class Var question Hi, In message "[ruby-talk:16499] Class Var question" on 01/06/16, Steve Tuckner <SAT / MULTITECH.com> writes: |Below is a snippet of code with what I want to do. However it doesn't work |as I would like. When I run it, I get | |{"test1"=>{"name"=>"Test 1"}, "test2"=>{"name"=>"Test 2"}, |"test3"=>{"name"=>"Test 3"}} |{"test1"=>{"name"=>"Test 1"}, "test2"=>{"name"=>"Test 2"}, |"test3"=>{"name"=>"Test 3"}} | |What I want is: | |{"test1"=>{"name"=>"Test 1}} |{"test2"=>{"name"=>"Test 2"}, "test3"=>{"name"=>"Test 3"}} | |What is the best way to get the class variable @@userVars defined in the |sub-class (for each sub-class that sub-classes the super class). Cool down and re-think what you want. Your program did not describe what you want. That's the reason you didn't get what you expected. The values of class variables are shared among subclasses. So the value and contents of @@userVars are same in every class. Probably you can use instance variables of classes. matz.