Method parameters Type

  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?

···

From: Sreedhar Kesanasetti <kesanasetti.sreedhar@citigroup.com>

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

···

On Mon, Apr 7, 2008 at 4:28 PM, Mike Blackwell <maiku41@sbcglobal.net> wrote:

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

--
Avdi

Avdi Grimm 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 Gawlowski
Twitter: twitter.com/cynicalryan

Rule of Open-Source Programming #37:

Duplicate effort is inevitable. Live with it.

···

On Mon, Apr 7, 2008 at 4:28 PM, Mike Blackwell <maiku41@sbcglobal.net> wrote:

Avdi Grimm 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. :slight_smile:

Avdi Grimm 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.

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

···

El Lunes, 7 de Abril de 2008, Phillip Gawlowski escribió:

> On Mon, Apr 7, 2008 at 4:28 PM, Mike Blackwell <maiku41@sbcglobal.net> > > wrote:

        from :0

--
Iñaki Baz Castillo

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.

···

On Mon, Apr 7, 2008 at 5:12 PM, Phillip Gawlowski <cmdjackryan@googlemail.com> wrote:

Ruby is?

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

--
Avdi

Avdi Grimm wrote:

···

On Mon, Apr 7, 2008 at 5:12 PM, Phillip Gawlowski > <cmdjackryan@googlemail.com> 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. :slight_smile:

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan

Zmodem has bigger bits, softer blocks, and tighter ASCII.

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

···

On 08.04.2008 00:53, Phillip Gawlowski wrote:

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

Avdi Grimm wrote:
> On Mon, Apr 7, 2008 at 5:12 PM, Phillip Gawlowski > > <cmdjackryan@googlemail.com> 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. :slight_smile: