From: Lars Haugseth Date: 2012-06-08T16:12:24+09:00 Subject: Re: Inexplicable Argument Error On 08.06.2012 02:14, I��aki Baz Castillo wrote: > 2012/6/6 Bartosz Dziewo��ski: > > Ruby methods ending in "=" are special: > > def foo=(var) > return 42 > end > > foo="HELLO" > => "HELLO" > > It returns "HELLO" instead of 42. So it's clear that the parses treats > those methods in a "different" way. The method is never called in your example. Instead, you assign a value to a local variable named "foo". def foo=(var) puts "foo was called with '#{var}'." 42 end Assignment to local variable, method is never called: foo="hello" => "hello" foo => "hello" Use explicit receiver to ensure we call the method: self.foo="hello" foo was called with 'hello'. => "hello" Call method by using Object#send: send(:foo=, "hello") foo was called with 'hello'. => 42 Notice how the two ways to call the method give different results. -- Lars Haugseth