"super" bug

L

Larry Edelstein

Hi all -

I misused the "super" keyword and I think I should have received an
error, but didn't.

I tried "super.my_method_name(..)" and got strange results. OK, fine,
I'm supposed to say "super(..)" or just "super". But shouldn't I get a
compilation error or something? Is the behavior of
"super.my_method_name(..)" even defined?

-larry
 
A

ara.t.howard

Hi all -

I misused the "super" keyword and I think I should have received an
error, but didn't.

I tried "super.my_method_name(..)" and got strange results. OK, fine,
I'm supposed to say "super(..)" or just "super". But shouldn't I get a
compilation error or something? Is the behavior of
"super.my_method_name(..)" even defined?

sure it is

( the_object_returned = super ).my_method_name( 42 )

'super' in ruby is not an object - it defers to the method of the same name in
the parent class and returns whatever that does.

regards.

-a
 
S

Stefan Rusterholz

Larry said:
Hi all -

I misused the "super" keyword and I think I should have received an
error, but didn't.

I tried "super.my_method_name(..)" and got strange results. OK, fine,
I'm supposed to say "super(..)" or just "super". But shouldn't I get a
compilation error or something? Is the behavior of
"super.my_method_name(..)" even defined?

-larry

as "a" already pointed out, super is a method call. I'd like to add,
that super and super() differ, super without parens calls the same
method in the parent class with all parameters passed to the current
method.

my regards
 
L

Larry Edelstein

unknown wrote:

Ah, right...it invokes the specified method on whatever happens to be
returned by the call to the superclass's method.

It's the downside of weakly typed languages - they make it easy to get
an oddball result like this. (Of course not knowing how to actually use
the language helps, too, heh heh.)

-larry
 

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,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top