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

Discussion in 'Ruby' started by Stephan Kämper, Jan 24, 2005.

  1. 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
    Stephan Kämper, Jan 24, 2005
    #1
    1. Advertising

  2. 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
    Michael Neumann, Jan 24, 2005
    #2
    1. Advertising

  3. 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
    Stephan Kämper, Jan 24, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Piotre Ugrumov
    Replies:
    3
    Views:
    368
    Nick Hounsome
    Jan 25, 2004
  2. Shark
    Replies:
    2
    Views:
    589
    Alf P. Steinbach
    Jan 13, 2006
  3. dolphin
    Replies:
    2
    Views:
    3,146
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
    Nov 2, 2007
  4. Jean-François Lemaire

    Answer to question 4.8 from the FAQ

    Jean-François Lemaire, Jan 4, 2008, in forum: C Programming
    Replies:
    4
    Views:
    283
    Jean-François Lemaire
    Jan 4, 2008
  5. Ying-Chieh Liao

    function overload (not operator overload)

    Ying-Chieh Liao, Oct 11, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    248
    Sherm Pendley
    Oct 11, 2004
Loading...

Share This Page