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

S

Stephan Kämper

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
 
M

Michael Neumann

Stephan said:
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
 
S

Stephan Kämper

Michael said:
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
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top