[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Method parameters Type

Sreedhar Kesanasetti

4/7/2008 8:07:00 PM

Hi All,

Unlike Java why does not ruby specify the method parameter types.
How can a caller know what type of parameter is the method expecting.

Same with the return value, ruby returns value of the last
statement, how can a caller know the return type.

Thanks
Sree
--
Posted via http://www.ruby-....

4 Answers

Gary Wright

4/7/2008 8:27:00 PM

0


On Apr 7, 2008, at 4:07 PM, Sreedhar Kesanasetti wrote:
> Hi All,
>
> Unlike Java why does not ruby specify the method parameter types.
> How can a caller know what type of parameter is the method expecting.
>
> Same with the return value, ruby returns value of the last
> statement, how can a caller know the return type.

Ultimately it depends on the availability of good class/method
documentation and the willingness of the programmer to read the
documentation.

The bigger issue is that your question assumes that the 'type'
of an object is something that can be statically specified by
the programmer at design time (e.g., by declaring an argument
to be an instance of a designated class) and this just is not
true with Ruby.

As long as an object responds to the message that are sent
to it (i.e. the methods that are called on it) then that
object is of the correct 'type'. This is generally referred
to in the Ruby community as 'duck typing'.

Check out <http://en.wikipedia.org/wiki/Duck_... to learn
more.

Gary Wright




Iñaki Baz Castillo

4/7/2008 8:47:00 PM

0

El Lunes, 7 de Abril de 2008, Sreedhar Kesanasetti escribi=C3=B3:
> =C2=A0 =C2=A0 =C2=A0Unlike Java why does not ruby specify the method para=
meter types.
> How can a caller know what type of parameter is the method expecting.

Because Ruby use dynamic dispatch, not static as Java.
PD: Is correct "dynamic dispatch" in English?


> =C2=A0 =C2=A0 =C2=A0Same with the return value, ruby returns value of the=
last
> statement, how can a caller know the return type.

Same.


=2D-=20
I=C3=B1aki Baz Castillo

Jason Roelofs

4/7/2008 9:23:00 PM

0

On Mon, Apr 7, 2008 at 4:47 PM, I=F1aki Baz Castillo <ibc@aliax.net> wrote:
> El Lunes, 7 de Abril de 2008, Sreedhar Kesanasetti escribi=F3:
>
> > Unlike Java why does not ruby specify the method parameter types.
> > How can a caller know what type of parameter is the method expecting.
>
> Because Ruby use dynamic dispatch, not static as Java.
> PD: Is correct "dynamic dispatch" in English?
>

No, dynamic dispatch is not the correct term here. Just dynamic (but
strong!) typing. Dynamic dispatch has to do with polymorphism:

http://en.wikipedia.org/wiki/Dynami...

Jason

Avdi Grimm

4/7/2008 9:28:00 PM

0

On Mon, Apr 7, 2008 at 5:23 PM, Jason Roelofs <jameskilton@gmail.com> wrote:
> No, dynamic dispatch is not the correct term here. Just dynamic (but
> strong!) typing. Dynamic dispatch has to do with polymorphism:

Dynamic dispatch is correct. Methods are dispatched dynamically on
the type of the receiver.

Perhaps you were thinking of *multiple* dispatch, which Ruby does not
support inherently.

--
Avdi