How can I invoke super class's method

My class include a Module and overwrite a method of the Module. In this
method, I want to invoke the Module’s method first. Just like
“super.method()” in Java. How can I do this?

Zhao Yi wrote:

My class include a Module and overwrite a method of the Module. In this
method, I want to invoke the Module’s method first. Just like
“super.method()” in Java. How can I do this?

Just the word super().
module M
def q(arg)
#
end
end
class K
include M
def q(arg)
#
super(arg)
end
end

super() calls ancestor’s function with the same name as the function
you’re currently in.

TPR.

Hi –

On Sun, 31 Aug 2008, Thomas B. wrote:

end
class K
include M
def q(arg)

super(arg)
end
end

super() calls ancestor’s function with the same name as the function
you’re currently in.

Keep in mind, though, that the semantics of super (which is a keyword,
rather than a method) are a bit different from regular method-calling
semantics:

super # call ancestor’s method with current arguments
super(a,b) # call with exactly the arguments (a,b)
super() # call with no arguments

It’s really the first one that’s the special case, as you can see.

David

Got it thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs