-1

How do you call a method in the most derived class of a ruby object?

For example, in Rails, one can have a controller that inherits from ApplicationController, or say, Devise::RegistrationsController. So, say I want the user to override some method in their controller, and call that override from the base class: What would be the best syntax for doing it?

diffeomorphism
  • 991
  • 2
  • 10
  • 27
  • What you have described is not the way in which inheritance works. Perhaps you could explain and ask how to accomplish your specific goal. – Wizard of Ogz Nov 03 '15 at 05:20
  • what I am asking is if there is anything like virtual inheritance on other languages? if `class B < A` and the code of `A::foo` wants to call `B::bar` – diffeomorphism Nov 03 '15 at 05:27

3 Answers3

2

There is nothing you need to do, method lookup always starts at the most-derived class. That is, after all, the whole point of overloading.

class A
  def foo
    bar
  end

  def bar
    :A
  end
end

class B < A
  def bar
    :B
  end
end

B.new.foo
# => :B
Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
0

Are you trying to use a method from, for example, UserController in lieu of the Devise RegistrationsController? Let me know what you are trying to accomplish specifically using code examples. :)

  • the actual reason I was trying to force a check on the inherited controller, this is the question with the original problem http://stackoverflow.com/a/33490887/1792701 – diffeomorphism Nov 03 '15 at 05:51
-1

what I am asking is if there is anything like virtual inheritance on other languages?

No, Ruby does not have this.

Wizard of Ogz
  • 12,543
  • 2
  • 41
  • 43