Shiwei Zhang ha escrito:
> I think Function Overloading in C++ is very meaningful.
It isn't.
> 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}]"
Ruby is such a complex language compared to C++ :)
class A
private
def _logon( uid, pwd, conn, privilege )
p uid, pwd, conn, privilege
end
public
def logon( uid, pwd = nil, conn = nil, privilege = nil )
if pwd == nil
# parse uid as "uid/pswd@host:port/service_name [AS
{SYSOPER|SYSDBA}]"
# and extract other vars.
uid =~ /(\S+)\/(\S+)\@(\S+:\S+)(?:\s+AS\s+(SYSOPER|SYSDBA))?/
uid, pwd, conn, privilege = $1, $2, $3, $4
end
_logon(uid, pwd, conn, privilege )
end
end
# user cannot see private method _logon
p A.instance_methods.grep /logon/
a = A.new
a.logon( 'gga', 'crap', 'host:2322')
a.logon( 'gga/crap@host:2322')
a.logon( 'gga/crap@host:2322 AS SYSOPER')