[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

"super" bug

Larry Edelstein

2/13/2007 6:20:00 AM

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

--
Posted via http://www.ruby-....

3 Answers

Ara.T.Howard

2/13/2007 6:29:00 AM

0

Stefan Rusterholz

2/13/2007 7:54:00 AM

0

Larry Edelstein wrote:
> 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

--
Posted via http://www.ruby-....

Larry Edelstein

2/13/2007 8:00:00 AM

0

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


> On Tue, 13 Feb 2007, Larry Edelstein wrote:
>
>> 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


--
Posted via http://www.ruby-....