Quick actions

cmd+k|ctrl+k

Navigation

Languages

call parent class method without super()

Snippet info

Language

Ruby

Visibility

public

Author

hyrious

Created

2018-12-28T14:03:40Z

Updated

2018-12-28T14:03:40Z

class A; def a() 42 end end
class B < A; def a() 24 end end
class B
    def b # call A#a => 42, instead of 24 from B#a
        self.class.superclass.instance_method(:a).bind(self).call
        # self.class => B
        # B.superclass => C
        # C.instance_method(:a) => unbound_method(:a), can not `call'
        # unbound_method(:a).bind(self) => method(:a), can be `call' now
    end
end
p B.new.b
INFO