From: Daniel Carrera Date: 2003-06-27T14:22:53+09:00 Subject: Re: method overloading? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Well, I guess that using a case statement would help a little. Maybe there is a really simple way of doing this and I just don't know it. On Fri, Jun 27, 2003 at 02:12:47PM +0900, Donglai Gong wrote: > Yes, this would solve the problem but it's not ideal or elegant, the > code is now much less obvious. > > For example: > > class Bank > def open(safe, combination) > ... > end > > def open(window) > ... > end > end > > is a lot more revealing than: > > class Bank > def open(*args) > if args.length == 1 > ... > elsif args.length == 2 > ... > end > end > end > > Thanks for the help though, it just feels like overloading could be > done in a simpler manner. > > Donglai > > On Friday, Jun 27, 2003, at 00:47 US/Eastern, Daniel Carrera wrote: > > >-----BEGIN PGP SIGNED MESSAGE----- > >Hash: SHA1 > > > >Does this help?: > > > >def my_method(*args) > > if args.length == 2 > > two_parameters_method(args) > > elsif args.length == 3 > > three_parameters_method(args) > > end > >end > > > >On Fri, Jun 27, 2003 at 01:43:42PM +0900, Donglai Gong wrote: > >>Is there a way to implement method overloading in ruby? Naively I > >>just > >>defined two methods with the same name with different number of > >>parameters...Ruby didn't like that. > >> > >>Donglai > >> > > > >- -- > >Daniel Carrera | OpenPGP fingerprint: > >Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 > >7A88 > >UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html > >-----BEGIN PGP SIGNATURE----- > >Version: GnuPG v1.2.2 (SunOS) > > > >iD8DBQE++8xOnxE8DWHf+OcRAl4DAKDRbjvOrfMXCThfwDS2ByiyuuxsbwCeLJNT > >kqbKGOYm5OUjay6wiiHtwjU= > >=kyCD > >-----END PGP SIGNATURE----- > > > - -- Daniel Carrera | OpenPGP fingerprint: Graduate TA, Math Dept | 6643 8C8B 3522 66CB D16C D779 2FDD 7DAC 9AF7 7A88 UMD (301) 405-5137 | http://www.math.umd.edu/~dcarrera/pgp.html -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (SunOS) iD8DBQE++9SmnxE8DWHf+OcRAmxRAKDDSYCSOnaR87+4eKWc2J0M70JQUACfZoy8 BSPYGujpe9mu9A+ui8YKBqk= =jgx7 -----END PGP SIGNATURE-----