From: Shiwei Zhang Date: 2007-01-16T15:21:42+09:00 Subject: Re: How to realize method/function overloading in Ruby? --------------010101010101050206000200 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Phrogz wrote: >Shiwei Zhang wrote: > > >>I think Function Overloading in C++ is very meaningful. And currently >>the case for me is: How I can make use of method/function overloading >>in Ruby? >> >> > >Can you provide us with a few real-world cases where you would want to >use method overloading in C++? In Ruby, duck-typing does away with some >of those cases, and we can show you how. > >If you show us what you are wanting to do, that makes it easier to >discuss the best ways to do it. (Unless, of course, you're just trying >to accomplish a checkmark in a feature list.) > > > > Thanks. My requirement is: I've had a method "logon(uid, pswd, conn = nil, privilege = nil)", but I want to add another method like "logon(easyconn)", where easyconn is in the format of "uid/pswd@host:port/service_name [AS {SYSOPER|SYSDBA}]" . I think I have 3 solutions to implement this: S1) Keep the existing method "logon(uid, pswd, conn = nil, privilege = nil)" unchanged, and add the method "logon(easyconn)" which will invoke "logon(uid, pswd, conn = nil, privilege = nil)". S2) Refactor the method "logon(uid, pswd, conn = nil, privilege = nil)", modify the body of this method in order that it can support the the format of "uid/pswd@host:port/service_name [AS {SYSOPER|SYSDBA}]". This solution is duck-typing. S3) Keep the existing method "logon(uid, pswd, conn = nil, privilege = nil)" unchanged, and add another method "logon1(easyconn)" which will invoke "logon(uid, pswd, conn = nil, privilege = nil)". Note: logon1 is a different name with logon. The method "logon(uid, pswd, conn = nil, privilege = nil)" has been a certified/tested mothod, and many applications have been based on it. I am used to thinking of S1), because it doesn't need regression test for the existing method "logon(uid, pswd, conn = nil, privilege = nil)". However, Ruby doesn't support method overloading, so I have to discard S1) and choose S3). But S3) seems not a good impression for users, because the new name "logon1" is not consist with the existing name "logon". The inconsistence might make users confused I think.So I want to apply S2), but it needs regression test, which is a burden. Thanks & Best Rgds, Shiwei --------------010101010101050206000200--