From: Massimiliano Mirra Date: 2002-09-29T20:22:40+09:00 Subject: Re: object attributes list On Fri, Sep 27, 2002 at 12:54:58AM +0900, ajksharma wrote: > HI, > I have a Object > Customer > .Customerid="Alfki" > .city = "Belin" > etc > I want to get a list of these attributes and their values, > Possibly in a hash form. > Customers = { "Customerid" => "Alfki", > "city" => "Belin" > } Put them in a hash in the first place. class Customer def initialize @data = { 'Customerid' => nil, 'city' => nil } end attr_reader :data def method_missing(id, *args, &block) possible_key = id.to_s is_setter = possible_key.chomp!('=') if @data.has_key?(possible_key) if is_setter @data[possible_key] = *args else return @data[possible_key] end else super end end end c = Customer.new c.Customerid = 'Alfki' c.city = 'Belin' p c.data >>> {"city"=>["Belin"], "Customerid"=>["Alfki"]} Massimiliano