From: Josh Cheek Date: 2010-11-14T06:42:02+09:00 Subject: Re: display instance variable values --0016e64651489284e20494f60ea0 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Nov 13, 2010 at 3: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 > > > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > replace the line "var.(display value somehow)" with "puts peep.instance_variable_get(var)" --0016e64651489284e20494f60ea0--