From: Greg Willits Date: 2010-10-31T05:11:32+09:00 Subject: Re: Dynamically reference instance vars Ryan Davis wrote in post #958245: > On Oct 30, 2010, at 12:27 , Greg Willits wrote: > >> I was hoping in Ruby that at least this was possible: >> >> myobject.send(iname) = ivalue >> --or-- >> myobject.send(iname, ivalue) > > You're confusing methods and variables. They're not the same, but you're > on the right track with the code above, but you'd be calling the getter, > not the setter. Check it: > > class X > attr_accessor :x # creates x and x= methods > end > > o = X.new > o.send("x=", 42) > p x I wasn't confusing them, I was hoping Ruby's send would be flexible enough to work with both of them (in conjunction with the accessors being defined). What I didn't think of in this context was Ruby's x= being considered the setter method and not just x, which I knew, and should have recognized -- so yep, that was the ticket. You win! :-) Sorry, no prizes :-( Thanks. -- gw -- Posted via http://www.ruby-forum.com/.