method overloading?

D

Donglai Gong

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
 
R

Ryan Pavlik

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

<shameless plug>

The StrongTyping module on RAA lets you do this:

def foo(*args)
overload(args, String) {
...
return ...
}

overload(args, String, String) {
...
return ...
}

...

overload_default args
end

Of course, if you don't care what type of object you want
specifically, you can just say "Object", and you can specify multiple
types like [String, NilClass].

</shameless plug>
 
D

Daniel Carrera

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ruby Application Archive.

http://raa.ruby-lang.org

It's analogous to CPAN, CTAN and the Vaults.


What is RAA? Is there any documentation for it? Thanks.

Donglai

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

<shameless plug>

The StrongTyping module on RAA lets you do this:

def foo(*args)
overload(args, String) {
...
return ...
}

overload(args, String, String) {
...
return ...
}

...

overload_default args
end

Of course, if you don't care what type of object you want
specifically, you can just say "Object", and you can specify multiple
types like [String, NilClass].

</shameless plug>


--
Ryan Pavlik <[email protected]>

"Ye don't like me? But we don't even know each other. I
bets we have a lot in common. Treachery and such. Yar." - 8BT

- --
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++9dcnxE8DWHf+OcRAvQDAKCHurhslqK8ufDgOGEhpWNqqW4NlACcCXFq
riuo3zsuczQp2ldBuDzbvu0=
=btKo
-----END PGP SIGNATURE-----
 
K

KONTRA Gergely

On 0627, Ryan Pavlik wrote:
[...]
The StrongTyping module on RAA lets you do this:

def foo(*args)
overload(args, String) {
...
return ...
}

overload(args, String, String) {
...
return ...
}

...

overload_default args
end
[...]

But this also doesn't allow one to later add a new case...
I guess it needs some help from the core of the language to work...
BTW I think dynamic type checking fits to the ruby design.

Gergo
 

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top