From: Phrogz Date: 2006-12-25T05:25:10+09:00 Subject: Re: Method equality; setting instance variables on Method instances Phrogz wrote: > A few questions about the code below: > 1) Why do m1 and m2 have different IDs but compare as equal? > 2) Why does m2 invoke the same old functionality when run? > 3) Why did my instance_variable_set not 'take'? Another data point on that last question: at least it looks like you can set/get instance variables on a Method instance in general: irb(main):001:0> m1 = Kernel.method( :system ) => # irb(main):002:0> m1.instance_variable_set( :@foo, :bar ) => :bar irb(main):003:0> m1.instance_variables => ["@foo"] irb(main):004:0> m1.instance_variable_get( :@foo ) => :bar In case it wasn't obvious, what I am trying to achieve with the above code is a stack-like method override/restore system. Each time you override a method, the method should store the name of the randomly-chosen alias for the old method. A workaround will be to store the stack of method names on the module itself (which I'll try next); nonetheless, I'm interested in why my original code didn't work as I expected.