From: Robert Klemme Date: 2009-03-03T02:13:57+09:00 Subject: Re: What does this statement do? On 02.03.2009 15:27, Jason Roelofs wrote: > On Mon, Mar 2, 2009 at 9:18 AM, Stanislaw Wozniak wrote: >> Stanislaw Wozniak wrote: >>> Hi Guys, >>> >>> I have been wondering what does this statement do and what does it set. >>> It interferes with my methods_missing handler: >>> >>> {code} >>> class MyClass >>> >>> something = "something else" >>> >>> end >>> {code} >> I guess this is assigning a string to a variable that is created in the >> MyClass scope. But my problem is that I have some setter methods that >> I'm using through method_missing, but method_missing is never triggered >> because it is assigning stuff just like in the example above. >> -- >> Posted via http://www.ruby-forum.com/. >> >> > > That statement is the same as calling MyClass.something=("something else") Actually, no. See Rick's excellent explanation. For test addicts: [oracle@ora01 ~]$ ruby y.rb test 1 foo called with 123 test 2 [oracle@ora01 ~]$ cat y.rb class X def self.foo=(a) printf "foo called with %p\n", a end end puts "test 1" X.foo = 123 class X puts "test 2" foo = 987 end [oracle@ora01 ~]$ > If you want method_missing to catch it, you need to define a > method_missing on the class itself, like this: > > class MyClass > > def self.method_missing(name, *args) > end > > end Won't help here, because the statement is interpreted as a local variable assignment. Kind regards robert