From: Stefano Crocco Date: 2009-10-24T00:19:19+09:00 Subject: Re: Setting attribute via send in Ruby 1.8.6 On Friday 23 October 2009, Charles Calvert wrote: > |Using Ruby 1.8.6. > | > |I've run into an instance in which I'd like to set attributes of an > |instance using the send method. I've looked around, but found > |nothing, most likely because I'm using the wrong search terms. > | > |Example: > | > |class A > | attr_reader :foo > | attr_writer :foo > |end > | > |a = A.new > |a.send("foo", "newval") > | > | > |I get the following error: "wrong number of arguments (1 for 0) > |(ArgumentError)" > | > |Am I correct in thinking that this is possible, and that I'm just > |going about it the wrong way? > | The method attr_writer generates has an equal sign appended to the name you give. This means that attr_writer :foo generates a method called foo=. So, if you want to call it using send, you need to write: a.send("foo=", "newval") I hope this helps Stefano