How do I call a super class method

前端 未结 5 816
栀梦
栀梦 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:30

    In Ruby 2.2, you can use Method#super_method now

    For example:

    class B < A
      def foo
        super + " world"
      end
    
      def bar
        method(:foo).super_method.call
      end
    end
    

    Ref: https://bugs.ruby-lang.org/issues/9781#change-48164 and https://www.ruby-forum.com/topic/5356938

提交回复
热议问题