3

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

Elmor
  • 4,775
  • 6
  • 38
  • 70
  • 1
    Take a look at this : http://stackoverflow.com/questions/1251178/calling-another-method-in-super-class-in-ruby – Ta Duy Anh Oct 13 '12 at 07:38
  • Yep, thanks for that. i hope ruby can do better than this, cause it's not as elegant as the rest of ruby – Elmor Oct 13 '12 at 07:49

1 Answers1

2

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

Elmor
  • 4,775
  • 6
  • 38
  • 70