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:
Tom.
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:
Tom.
2010/2/23 Tom Ten T. [email protected]:
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
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
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs