On Fri, Oct 23, 2009 at 6:40 PM, Charles Calvert <cbciv / yahoo.com> wrote: > On Fri, 23 Oct 2009 17:18:22 +0200, Robert Klemme > <shortcutter / googlemail.com> wrote in > <7kdvpuF37n3jvU1 / mid.individual.net>: > >>On 10/23/2009 05:10 PM, 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. ¨Β§φμοολεδ αςουξδβυζουξ>>> nothing, most likely because I'm using the wrong search terms. > > [snip example] > >>> 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? >> >>Yes. >> >>... > > The suspense almost killed me! > >>:-) >> >>You need to use the _setter_ method with #send - which happens to be >>called "foo=" in your case. > > Ah, now the lightbulb goes off. ¨Β σθουμδ θαφε ςενενβεςεδ τθ> convention of having the setter have an equals sign as part of the > name. ¨Β§ν τουσεδ το μαξηυαηετθατ δετεςνιξχθιγαγγεσσος ισ υσεδ > based on which side of the assignment it appears rather than actually > using a method name to syntactically simulate assignment. You can achieve what you want if instead of using attr_writer you roll yourwn. I remember a discussion in this list regarding something like: class A def a *args return @a if args.empty? @a = args[0] end end a = A.new a.a #=> nil a.a 4 #=> 4 a.a #=> 4 With this you can do a.send(:a, 4) Jesus.