Method parameters Type

Discussion in 'Ruby' started by Sreedhar Kesanasetti, Apr 7, 2008.

  1. 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-forum.com/.
     
    Sreedhar Kesanasetti, Apr 7, 2008
    #1
    1. Advertising

  2. Sreedhar Kesanasetti

    Gary Wright Guest

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

    Gary Wright
     
    Gary Wright, Apr 7, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jerry051
    Replies:
    2
    Views:
    756
    Oliver Sturm
    Aug 2, 2005
  2. Howard
    Replies:
    2
    Views:
    379
    Michiel Salters
    Jul 4, 2003
  3. Rolf Magnus
    Replies:
    1
    Views:
    331
    ding feng
    Jul 4, 2003
  4. heyo
    Replies:
    3
    Views:
    919
    Dan Pop
    Apr 1, 2004
  5. www
    Replies:
    5
    Views:
    297
    Daniel Pitts
    Nov 7, 2007
Loading...

Share This Page