From: Daniel Cremer Date: 2004-08-16T23:23:23+09:00 Subject: Re: returning symbols On Mon, 2004-08-16 at 14:53, 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 } Interesting example... What I don't understand is how would you implement object pools in Ruby ? If I understand correctly with object pools you often have data representing state stored separately. Then when needed you can grab an instance of the object from the pool and populate it with this data. For an example like that I would like to have a base-class that implements a persist() method. This way developers working on a class can inherit this class and simply pass the objects representing state to this persist() method. def persist(*state_objs) ... persistent_objects = Array.new() state_objs.each { |obj| persistent_objects << obj } ... end >From then on it could be included into object pools with no further work from the developer. But this is were I have problems. Implementing this in the base class such that it can take any list of variables without any knowledge of their names and being able to get back to the contents of the variables to store the state before returning the object to the pool. I hope this makes sense, I might be confusing myself :) On Mon, 2004-08-16 at 14:04, Dave Thomas wrote: > You could use a closure, but more typically you'd want to enapsulate he > set of variables into a class and return that class. Could someone elaborate on the part about returning a class. I'm not sure if I captured the full meaning. thanks, Daniel