Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling a parent::method from a child::method

Good day, i'm new to ruby. I want to know how to run a parent method from a method of a child class ? in java it would be like

class Child
  ..
  def something_else
    super.something
  end
end

and in php

parent::method_name();

And could you tell me how to do it in Ruby? found only this, and it's kind of ugly using alias_method_chain

like image 838
Elmor Avatar asked Sep 24 '26 23:09

Elmor


1 Answers

as Taiki suggested the comment in another thread stated

class B < A

  alias :super_a :a

  def a
    b()
  end
  def b
    super_a()
  end
end

hope there are other ways...

UPDATE:

at long last, call super() instead of super_a(). not sure what it does completely though

like image 116
Elmor Avatar answered Sep 26 '26 11:09

Elmor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!