[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Over Loading

Selvaraj Subbaian

3/27/2008 6:18:00 AM

Hai All,

Question looks like simple Why ruby is not supporting over loading??

I think we can pass any number of argument as an array to method. is
this the reason or any other ???
--
Posted via http://www.ruby-....

4 Answers

???? ?????????

3/27/2008 9:34:00 AM

0

Because of Ruby type system

You cant write

def test(int i)

end

def test(string s)

end

In Ruby this is
def test(arg)
end

So you can do something like this
def test(arg)
if arg.is_a?(String)
else
end
end

Robert Klemme

3/27/2008 12:09:00 PM

0

2008/3/27, Selvaraj Subbaian <selvaraj@srishtisoft.com>:
> Question looks like simple Why ruby is not supporting over loading??

You would have to ask Matz for details. Here are some potential reasons:

- Ruby is dynamically typed which makes overloading based on argument
types impossible; you could only overload on argument list structure
(mostly number of args)

- argument list structure based overloading is seldom useful and in
those cases the implementer can do it himself - no need to burden the
language with this.

- because of Ruby's dynamic nature methods that are overloaded based
on argument type in other languages often fall into one and need not
be overloaded.

> I think we can pass any number of argument as an array to method. is
> this the reason or any other ???

This might be part of the reason (see above).

Kind regards

robert

--
use.inject do |as, often| as.you_can - without end

Florian Gilcher

3/27/2008 12:31:00 PM

0

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


On Mar 27, 2008, at 10:34 AM, =D0=98=D0=B2=D0=B0=D0=BD =
=D0=95=D0=B2=D1=82=D1=83=D1=85=D0=BE=D0=B2=D0=B8=D1=87 wrote:
>
>
> So you can do something like this
> def test(arg)
> if arg.is_a?(String)
> else
> end
> end
>


There are some projects out there that allow pattern matching on =20
arguments to some extend. (search for "match" on rubyforge)

Basically, they work by defining a proxy method that does the pattern =20=

matching and then calling some predefined procs. Essentially,
they define this test-Method dynamically.
This is not overloading in a strict sense, but it comes close.

Greetings
Florian Gilcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkfrk3MACgkQJA/zY0IIRZZImgCeLw1Db8i/wyhlNP+0jrlXpjUD
RaUAn0ecOSw8Qd5wOzmwI/LHkL5rBncb
=3D/pKG
-----END PGP SIGNATURE-----

Iñaki Baz Castillo

3/27/2008 1:30:00 PM

0

MjAwOC8zLzI3LCBTZWx2YXJhaiBTdWJiYWlhbiA8c2VsdmFyYWpAc3Jpc2h0aXNvZnQuY29tPjoK
PiAgSSB0aGluayB3ZSBjYW4gcGFzcyBhbnkgbnVtYmVyIG9mIGFyZ3VtZW50IGFzIGFuIGFycmF5
IHRvIG1ldGhvZC4gaXMKPiAgdGhpcyB0aGUgcmVhc29uIG9yIGFueSBvdGhlciA/Pz8KCkJldHRl
ciB0aGFuIGFuIEFycmF5IHlvdSBjYW4gcGFzcyBhIEhhc2ggLCBzbyB5b3Uga2VlcCB0aGUgdmFy
aWFibGUgbmFtZToKCm9iamV0Lm15X21ldGhvZCggeyAibnVtIj0+MjMxMyAsICJuYW1lIj0+Ik15
IE5hbWUiLCAicGhvbmUiPT4iKzM0MjMyMzQzMjQzIiB9ICkKCgpkZWYgbXlfbWV0aG9kICggdmFy
aWFibGVzID0ge30gKQoJcHV0cyAiTXkgbmFtZSBpcyIgKyB2YXJpYWJsZXNbIm5hbWUiXQoJcHV0
cyAiTXkgaWQgbnVtIGlzIiArIHZhcmlhYmxlc1sibnVtIl0udG9faQplbmQKCkFGQUlLIFJ1YnlP
blJhaWxzIHVzZXMgdGhpcyB3YXkgYSBsb3QuCgoKLS0gCknDsWFraSBCYXogQ2FzdGlsbG8KPGli
Y0BhbGlheC5uZXQ+Cg==