From: Ammar Ali Date: 2010-11-14T06:47:07+09:00 Subject: Re: display instance variable values On Sat, Nov 13, 2010 at 11:08 PM, John Sayeau wrote: > If I have a people class with instance variables @name @age and @gender > and an instance of that class called peep (justa an example). > If I want to see all the available instance variables I can do: > > p peep.instance_variables => ["@age", "@name", "@gender"] > > Is there a way to get the value of those instance variables for the peep > instance without calling a class method ? Say there is full r/w access > to the instance variables. > > Something like: > > > peep.instance_variables.each do |var| > >   var.(display value somehow) > > end What are you trying to do? This seems a little strange to me. In any case, if the instance variable are readable or accessible, i.e. defined with attr_reader, attr_accessor, or have methods to get them, you can use send to get at their values: peep.instance_variables.each do |var| puts peep.send(var.sub('@', '')) end Again, it feels a little strange to me. HTH, Ammar