# Calling a redefined method higher up the ancestor hierarchy

**URL:** <https://www.ruby-forum.com/t/calling-a-redefined-method-higher-up-the-ancestor-hierarchy/183983>\
**Category:** Ruby\
**Created:** [February 23, 2010, 1:42pm UTC](https://www.ruby-forum.com/t/calling-a-redefined-method-higher-up-the-ancestor-hierarchy/183983 "2010-02-23T13:42:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [February 23, 2010, 1:42pm UTC](https://www.ruby-forum.com/t/calling-a-redefined-method-higher-up-the-ancestor-hierarchy/183983/1 "2010-02-23T13:42:54Z")

</div>

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:

> <https://gist.github.com/tomtt/312104>

Tom.

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [February 23, 2010, 2:01pm UTC](https://www.ruby-forum.com/t/calling-a-redefined-method-higher-up-the-ancestor-hierarchy/183983/2 "2010-02-23T14:01:37Z")

</div>

2010/2/23 Tom Ten T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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:  
> [test\_spec.rb · GitHub](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

---

<div class="post-metadata">

**Author:** ![tomtt](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e47c2d/32.png) [@tomtt](https://www.ruby-forum.com/u/tomtt)\
**Post date:** [February 23, 2010, 3:01pm UTC](https://www.ruby-forum.com/t/calling-a-redefined-method-higher-up-the-ancestor-hierarchy/183983/3 "2010-02-23T15:01:27Z")

</div>

Robert K. wrote:

> You can get an unbound method and bind it to the instance:  
> Object.instance\_method(:method).bind(s).call(:foo) == desired\_method

Thanks, that fixed it!

Tom.
