From: Robert Klemme Date: 2004-08-17T03:01:00+09:00 Subject: Re: returning symbols "Daniel Cremer" schrieb im Newsbeitrag news:1092660434.3941.27.camel@linux.site... > I want to write a method to store a list of some instance variables in > an Array that will later be run through to access their data. Normally > in another language I would do this by passing them by reference when I > store them into the Array. > > Using the object_id doesn't work because that's to the object the > variable is pointing to and this may change. > So, to sum it up: > > Is there a way to get variables to return their symbol so you can access > what they will be referencing in the future ? If I do understand correctly you want to store "self" together with the information which members of "self" to retrieve. Others presented solutions already, here is another one that is similar to the closure approach in that it uses an array of elements that store "self" and an accessor for a certain value but uses method instances instead: class Foo attr_accessor :bar, :baz, :name end f = Foo.new accessors = [:bar, :baz, :name].map { |s| f.method s } p accessors.map { |acc| acc.call } f.bar = "bar" f.baz = "baz" f.name = "name" p accessors.map { |acc| acc.call } f.bar = "BAR" f.baz = "BAZ" f.name = "NAME" p accessors.map { |acc| acc.call } Dunno which is more efficient though. Kind regards robert