From: Sam McCall Date: 2004-08-12T19:26:16+09:00 Subject: Re: getting object attributes Joe Laughlin wrote: > I want to do something similar to this: > > class Foo > @goo = 2 > @boo = 5 > end > > foo = Foo.new > > ["goo", "boo"].each do |attribute| > puts foo.attribute # should print out 2 on the first loop, 5 on the > second loop > end ["@goo","@boo"].each do |attribute| puts foo.instance_variable_get attribute end Also: foo.instance_variables.each do |attribute| puts foo.instance_variable_get attribute foo.instance_variable_set nil end Hope this helps. Sam