# Method parameters Type

**URL:** <https://www.ruby-forum.com/t/method-parameters-type/134103>\
**Category:** Ruby\
**Created:** [April 7, 2008, 10:06pm UTC](https://www.ruby-forum.com/t/method-parameters-type/134103 "2008-04-07T22:06:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sree1083](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@sree1083](https://www.ruby-forum.com/u/sree1083)\
**Post date:** [April 7, 2008, 10:06pm UTC](https://www.ruby-forum.com/t/method-parameters-type/134103/1 "2008-04-07T22:06:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sree1083](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@sree1083](https://www.ruby-forum.com/u/sree1083)\
**Post date:** [April 7, 2008, 10:27pm UTC](https://www.ruby-forum.com/t/method-parameters-type/134103/2 "2008-04-07T22:27:43Z")

</div>

On Apr 7, 2008, at 4:07 PM, Sreedhar K. 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\_typing](http://en.wikipedia.org/wiki/Duck_typing) to learn  
more.

Gary W.

---

<div class="post-metadata">

**Author:** ![sree1083](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@sree1083](https://www.ruby-forum.com/u/sree1083)\
**Post date:** [April 7, 2008, 10:48pm UTC](https://www.ruby-forum.com/t/method-parameters-type/134103/3 "2008-04-07T22:48:30Z")

</div>

El Lunes, 7 de Abril de 2008, Sreedhar K. escribiÃ³:

> Â Â Â 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?

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

Same.

---

<div class="post-metadata">

**Author:** ![sree1083](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@sree1083](https://www.ruby-forum.com/u/sree1083)\
**Post date:** [April 7, 2008, 11:29pm UTC](https://www.ruby-forum.com/t/method-parameters-type/134103/4 "2008-04-07T23:29:39Z")

</div>

On Mon, Apr 7, 2008 at 5:23 PM, Jason R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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.

---

<div class="post-metadata">

**Author:** ![sree1083](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8e7dd6/32.png) [@sree1083](https://www.ruby-forum.com/u/sree1083)\
**Post date:** [April 7, 2008, 11:23pm UTC](https://www.ruby-forum.com/t/method-parameters-type/134103/5 "2008-04-07T23:23:46Z")

</div>

On Mon, Apr 7, 2008 at 4:47 PM, Iñaki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> El Lunes, 7 de Abril de 2008, Sreedhar K. escribió:
> 
> > ```
> > 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:

> **[Dynamic dispatch](https://en.wikipedia.org/wiki/Dynamic_dispatch)**
>
> In computer science, dynamic dispatch is the process of selecting which implementation of a polymorphic operation (method or function) to call at run time. It is commonly employed in, and considered a prime characteristic of, object-oriented programming (OOP) languages and systems.
> Object-oriented systems model a problem as a set of interacting objects that enact operations referred to by name. Polymorphism is the phenomenon wherein somewhat interchangeable objects each expose an operation of...

Jason
