Calling method in parent class from subclass methods in Ruby

If the method is the same name, i.e. you’re overriding a method you can simply use super. Otherwise you can use an alias_method or a binding.

class Parent
  def method
  end
end

class Child < Parent
  alias_method :parent_method, :method
  def method
    super
  end

  def other_method
    parent_method
    #OR
    Parent.instance_method(:method).bind(self).call
  end
end

Leave a Comment