Method parameters Type

  • Thread starter Sreedhar Kesanasetti
  • Start date
S

Sreedhar Kesanasetti

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
 
G

Gary Wright

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> to learn
more.

Gary Wright
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,289
Messages
2,571,448
Members
48,126
Latest member
ToneyChun2

Latest Threads

Top