How do I call a super class method

前端 未结 5 824
栀梦
栀梦 2020-12-24 01:44

I have two classes A, and B. Class B overrides the foo method of class A. Class B has a b

5条回答
  •  清歌不尽
    2020-12-24 02:10

    Based on @Sony's answer.

    In case when you want to call the method method on some my_object and it's already overriden somewhere several classes higher (like for the Net::HTTPRequest#method), instead of doing .superclass.superclass.superclass use the:

    Object.instance_method(:method).bind(my_object)
    

    Like this:

    p Object.instance_method(:method).bind(request).call(:basic_auth).source_location
    

提交回复
热议问题