From: Martin Hart Date: 2004-01-19T02:40:31+09:00 Subject: Re: setting instance variable "dynamically" On Sunday 18 January 2004 17:29, Bauduin Raphael wrote: > I saw in the pickaxe there's a way to call methods dynamically, with > send("method_name"): > > "test".send("length") # 4 > > What I want to do is set a variable this way. Is it possible? class MyClass def initialize @name = "fred" end end m = MyClass.new m.instance_eval { @name = "freda" } var = "name" m.instance_eval("@#{var} = 'frederick'") the second is a bit messy - I'm sure there is an easier way :-) Cheers, Martin