Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > A question (and answer) for the Ruby FAQ: override and overload

Reply
Thread Tools

A question (and answer) for the Ruby FAQ: override and overload

 
 
Stephan Kämper
Guest
Posts: n/a
 
      01-24-2005
Hi all,

before I go ahead and post my proposal directly to the FAQ site, I
though I'd better share the proposal here...

I tend to add this question, as it regularly is touched here in
discussions and questions:

What's with 'overloading' and 'overriding' methods in Ruby? And what's
the difference between them anyway?

What do you think about it? There were lengthy threads about it, e.g.
the one starting at ruby-talk 51156 with well over 150 postings...

Happy rubying

Stephan
 
Reply With Quote
 
 
 
 
Michael Neumann
Guest
Posts: n/a
 
      01-24-2005
Stephan Kämper wrote:
> Hi all,
>
> before I go ahead and post my proposal directly to the FAQ site, I
> though I'd better share the proposal here...
>
> I tend to add this question, as it regularly is touched here in
> discussions and questions:
>
> What's with 'overloading' and 'overriding' methods in Ruby? And what's
> the difference between them anyway?


Overloading usually means in C++ or Java:

void my_method();
void my_method(int arg);
void my_method(int arg, char* x);

I.e. static polymorphism based on method signatures (the matching method
is found at compile time, hence "static").
In Ruby, we don't have this kind of polymorhphism. Okay we can emulate
this using:

def my_method(*args, &block)
end

But, I don't count this.

Overriding is probably another term for "overwriting" a method. That's
simply if you redefine a method.

Regards,

Michael


 
Reply With Quote
 
 
 
 
Stephan Kämper
Guest
Posts: n/a
 
      01-24-2005
Michael Neumann wrote:
> Stephan Kämper wrote:
>
>> before I go ahead and post my proposal directly to the FAQ site, I
>> though I'd better share the proposal here...
>>
>> I tend to add this question, as it regularly is touched here in
>> discussions and questions:
>>
>> What's with 'overloading' and 'overriding' methods in Ruby? And what's
>> the difference between them anyway?

>
>
> Overloading usually means in C++ or Java:
>
> void my_method();
> void my_method(int arg);
> void my_method(int arg, char* x);
>
> I.e. static polymorphism based on method signatures (the matching method
> is found at compile time, hence "static").
> In Ruby, we don't have this kind of polymorhphism. Okay we can emulate
> this using:


Yes, I know that. I just suggested to have this question (and answer)
added to the FAQ. And I actually volunteer to do so.

Happy rubying

Stephan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the different between override overload and hide? dolphin C++ 2 11-02-2007 11:15 AM
How does overload work in ruby? Shuaib Zahda Ruby 4 10-22-2007 12:31 PM
operator new override/overload? Shark C++ 2 01-13-2006 08:32 AM
function overload (not operator overload) Ying-Chieh Liao Perl Misc 3 10-11-2004 11:24 AM
How use the overload of>> (or<<) of a class in the overload of << and >> of another class? Piotre Ugrumov C++ 3 01-25-2004 08:08 PM



Advertisments