Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Calling a redefined method higher up the ancestor hierarchy

Reply
Thread Tools

Calling a redefined method higher up the ancestor hierarchy

 
 
Tom Ten Thij
Guest
Posts: n/a
 
      02-23-2010
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

Tom.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      02-23-2010
2010/2/23 Tom Ten Thij <(E-Mail Removed)>:
> 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/

 
Reply With Quote
 
 
 
 
Tom Ten Thij
Guest
Posts: n/a
 
      02-23-2010
Robert Klemme 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.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a method of a base class that is redefined in a extendedclass robbie.desutter@gmail.com Java 5 12-04-2007 09:11 AM
XSLT extracting certain descendants to higher level outside of ancestor rbrunn@think-cell.com XML 1 10-27-2006 06:23 PM
Calling function residing on Ancestor page from child page M B HONG 20 Javascript 2 12-13-2005 02:10 AM
Array.sort when it's items are String inheritors with redefined <=> works like if not redefined MiG Ruby 8 10-19-2005 03:48 PM
Accessing higher security level from higher security level nderose@gmail.com Cisco 0 07-11-2005 10:20 PM



Advertisments