# Re: Method parameters Type

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

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [April 7, 2008, 10:30pm UTC](https://www.ruby-forum.com/t/re-method-parameters-type/134109/1 "2008-04-07T22:30:03Z")

</div>

From: Sreedhar K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> > Unlike Java why does not ruby specify the method parameter types.

Because, unlike Java, Ruby is not a strongly typed language.

> > How can a caller know what type of parameter is the method expecting.

Read the method’s documentation?

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [April 7, 2008, 10:44pm UTC](https://www.ruby-forum.com/t/re-method-parameters-type/134109/2 "2008-04-07T22:44:20Z")

</div>

On Mon, Apr 7, 2008 at 4:28 PM, Mike B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Because, unlike Java, Ruby is not a strongly typed language.

To be pedantic, both Java and Ruby are strongly typed. However, Java  
is statically types, and Ruby is dynamically typed.

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [April 7, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/re-method-parameters-type/134109/3 "2008-04-07T23:13:08Z")

</div>

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

Avdi G. wrote:  
| On Mon, Apr 7, 2008 at 4:28 PM, Mike B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:  
|\> Because, unlike Java, Ruby is not a strongly typed language.  
|  
| To be pedantic, both Java and Ruby are strongly typed. However, Java  
| is statically types, and Ruby is dynamically typed.  
|

Ruby is?

irb(main):001:0\> t = String.new  
=\> “”  
irb(main):002:0\> t.class  
=\> String  
irb(main):003:0\> t = 1  
=\> 1  
irb(main):004:0\> t.class  
=\> Fixnum  
irb(main):005:0\> exit

Doesn’t look like it to me, since I can change the type of a variable  
with ease.

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)

Rule of Open-Source Programming #37:

Duplicate effort is inevitable. Live with it.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkf6jiUACgkQbtAgaoJTgL9AOgCfU5pDjiz+K1RP35cLhk9xZnlz  
63AAoIKEeH+TUqC82uUoIHke3v+FpnzW  
=9FdL  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [April 7, 2008, 11:28pm UTC](https://www.ruby-forum.com/t/re-method-parameters-type/134109/4 "2008-04-07T23:28:28Z")

</div>

On Mon, Apr 7, 2008 at 5:12 PM, Phillip G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ruby is?
> 
> Doesn’t look like it to me, since I can change the type of a variable  
> with ease.

You’re confusing static typing and strong typing.

In a weakly-typed language, like C, it is possible to cast an integer  
as a, for instance, a char\*, and then call string functions like  
sprintf() on it and the compiler will compile it, the runtime will run  
it, and it will wreak whatever havoc you please. Most high-level  
languages are strongly-typed, these days - neither Java or Ruby will  
allow you to call a String method on an Integer. You can assign  
whatever object you want to a variable in Ruby - hence _dynamic_  
typing - but that object will only ever allow you to call supported  
methods on it; otherwise you’ll get a NoMethodError. Hence _strong_  
typing.

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [April 7, 2008, 11:27pm UTC](https://www.ruby-forum.com/t/re-method-parameters-type/134109/5 "2008-04-07T23:27:18Z")

</div>

El Lunes, 7 de Abril de 2008, Phillip G.  
escribió:\>

> Doesn’t look like it to me, since I can change the type of a variable  
> with ease.

No, look at the following example:

irb(main):001:0\> text = "The number is: "  
=\> "The number is: "

irb(main):002:0\> number = 25  
=\> 25

irb(main):003:0\> puts text + number  
TypeError: can’t convert Fixnum into String  
from (irb):3:in `+’  
from (irb):3  
from :0

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [April 8, 2008, 11:12pm UTC](https://www.ruby-forum.com/t/re-method-parameters-type/134109/6 "2008-04-08T23:12:46Z")

</div>

On 08.04.2008 00:53, Phillip G. wrote:

> |  
> | methods on it; otherwise you’ll get a NoMethodError. Hence _strong_  
> | typing.  
> |
> 
> Thanks for the enlightenment. 🙂

Another way to put it would be that Ruby’s variables are type-less,  
while objects do have a specific type. While we’re at it: type !=  
class. Basically the type is defined by all operations (aka methods)  
usable on an instance - not the class it was created from.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [April 8, 2008, 12:53am UTC](https://www.ruby-forum.com/t/re-method-parameters-type/134109/7 "2008-04-08T00:53:58Z")

</div>

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

Avdi G. wrote:  
| On Mon, Apr 7, 2008 at 5:12 PM, Phillip G.  
| [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
|\> Ruby is?  
|\>  
|\> Doesn’t look like it to me, since I can change the type of a variable  
|\> with ease.  
|  
| You’re confusing static typing and strong typing.  
|  
| In a weakly-typed language, like C, it is possible to cast an integer  
| as a, for instance, a char\*, and then call string functions like  
| sprintf() on it and the compiler will compile it, the runtime will run  
| it, and it will wreak whatever havoc you please. Most high-level  
| languages are strongly-typed, these days - neither Java or Ruby will  
| allow you to call a String method on an Integer. You can assign  
| whatever object you want to a variable in Ruby - hence _dynamic_  
| typing - but that object will only ever allow you to call supported  
| methods on it; otherwise you’ll get a NoMethodError. Hence _strong_  
| typing.  
|

Thanks for the enlightenment. 🙂

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)

Zmodem has bigger bits, softer blocks, and tighter ASCII.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkf6pcwACgkQbtAgaoJTgL9trwCghb7DYangJvsq/ktpceHh12FD  
004AnikbmUhG0gwWUJywu43qfbPa76sK  
=b6S6  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![asplake](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@asplake](https://www.ruby-forum.com/u/asplake)\
**Post date:** [April 8, 2008, 11:33pm UTC](https://www.ruby-forum.com/t/re-method-parameters-type/134109/8 "2008-04-08T23:33:16Z")

</div>

Avdi G. wrote:

> To be pedantic, both Java and Ruby are strongly typed. However, Java  
> is statically types, and Ruby is dynamically typed

Indeed. I stand linguistically admonished. 🙂
