From: "Weirich, James" Date: 2004-01-19T23:32:30+09:00 Subject: Re: setting instance variable "dynamically" > > The following will work with arbitrary objects ... > > > > obj.instance_eval("lambda { |v| @a = v }").call(value) > > Well, you can do it simpler, even if you *want* to use > instance_eval. No need for a lambda: > > irb(main):001:0> class Foo > irb(main):002:1> def test(obj) > irb(main):003:2> instance_eval("@x=obj") > irb(main):004:2> end > irb(main):005:1> end I stand corrected. For some reason I thought that the value of 'obj' wouldn't be available inside of an instance_eval. > > At this point you must be thinking: "Why don't I just use > > instance_variable_set?" > > I'd love to see the answer to this question you'd suggest. :-)) The question was meant to be rhetorical, although with the simplification the choice is less clear. -- -- Jim Weirich / Compuware -- FWP Capture Services -- Phone: 859-386-8855