Reference to super instance

D

Danny

Hi,

Is there a way (or Ruby way?) to get the reference to the super instance
of an object? I need the reference as the starting point in a recursive
call, so simply using alias_method (as suggested by previous post) will
not work around the problem. Thank you very much!
 
R

Robert Klemme

Danny said:
Hi,

Is there a way (or Ruby way?) to get the reference to the super
instance of an object? I need the reference as the starting point in
a recursive call, so simply using alias_method (as suggested by
previous post) will not work around the problem. Thank you very much!

What do you mean by "super instance"? Ruby is not C++ - you cannot (and
need not) cast a reference to another type simply because references are
typeless.

If you just want to call the implementation of a method in the super class,
simply use super:

class Base
def foo() puts "base" end
end

class Derived < Base
def foo() super; puts "derived" end
end
base
derived
=> nil
Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,966
Members
47,513
Latest member
JeremyLabo

Latest Threads

Top