From: "Ara.T.Howard" Date: 2004-08-16T23:51:00+09:00 Subject: Re: returning symbols On Mon, 16 Aug 2004, T. Onoma wrote: > On Monday 16 August 2004 08:47 am, Daniel Cremer wrote: >> Is there a way to get variables to return their symbol so you can access >> what they will be referencing in the future ? > > class C > attr_accessor :a, :b, :c > def initialize > @a, @b, @c = 1, 2, 3 > end > def bump > @a, @b, @c = 100, 200, 300 > end > def ref > return [ lambda { @a }, lambda { @b }, lambda { @c } ] > end > end > > c = C.new > v = c.ref > v.each { |q| puts q.call } > c.bump > v.each { |q| puts q.call } > > -- > T. what does this give you over this? ~ > cat a.rb class C VARS = :a, :b, :c VARS.each{|v| attr_accessor v} def initialize @a, @b, @c = 1, 2, 3 end def bump @a, @b, @c = 100, 200, 300 end def ref VARS end end c = C.new vars = c.ref vars.each { |v| puts(c.send(v)) } c.bump vars.each { |v| puts(c.send(v)) } ~ > ruby a.rb 1 2 3 100 200 300 what am i missing here? -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================