2010/2/23 Tom Ten Thij <tomtt.rails / gmail.com>:
> I have a situation where an object has redefined the method method. Is
> there a way to call the original method method as provided by the Object
> class on it?
>
> Specifically, I would like to make the following spec pass:
> http://gist.github.com/312104

You can get an unbound method and bind it to the instance:

irb(main):001:0>     class TestClass
irb(main):002:1>       def foo
irb(main):003:2>         :foo
irb(main):004:2>       end
irb(main):005:1>     end
=> nil
irb(main):006:0>     s = TestClass.new
=> #<TestClass:0x1015c230>
irb(main):007:0>     desired_method = s.method(:foo)
=> #<Method: TestClass#foo>
irb(main):008:0>     class TestClass
irb(main):009:1>       def method
irb(main):010:2>         raise "I do not want to call this method"
irb(main):011:2>       end
irb(main):012:1>     end
=> nil
irb(main):013:0>
Object.instance_method(:method).bind(s).call(:foo) == desired_method
=> true

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/