naming parameters in the method calls

Discussion in 'Ruby' started by aidy, Sep 13, 2006.

  1. aidy

    aidy Guest

    Hi,

    In BASIC, it is possible to name the parameters in the method calls


    call:

    test_info(test_description := "Check that window displayed is correct",

    expected_result := "Correct image is displayed")



    method

    sub test_info (test_description, expected_result)

    Is it possible to do the same in Ruby?

    Thanks for your help

    aidy
    aidy, Sep 13, 2006
    #1
    1. Advertising

  2. On 13/09/06, aidy <> wrote:
    > Hi,
    >
    > In BASIC, it is possible to name the parameters in the method calls
    >
    >
    > call:
    >
    > test_info(test_description := "Check that window displayed is correct",
    >
    > expected_result := "Correct image is displayed")
    >
    >
    >
    > method
    >
    > sub test_info (test_description, expected_result)
    >
    > Is it possible to do the same in Ruby?
    >
    > Thanks for your help
    >
    > aidy
    >
    >
    >


    I do believe this might be a new feature in Ruby 2.0? I'm not sure if
    it's confirmed though.

    In the meantime you can kind of fake it using hashes. Ruby is clever
    enough to know when to convert an argument list to a hash like so:
    def talk(params)
    puts "Hello, I am #{params[:name]} and I am #{params[:age]} years old"
    end
    talk:)name=>"Bob",:age=>27)

    Farrel
    Farrel Lifson, Sep 13, 2006
    #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. Honne Gowda A
    Replies:
    2
    Views:
    857
    Karl Heinz Buchegger
    Oct 31, 2003
  2. andy6
    Replies:
    2
    Views:
    747
    andy6 via DotNetMonster.com
    Jun 9, 2006
  3. Harman
    Replies:
    1
    Views:
    2,489
    Moiristo
    Jul 28, 2006
  4. Richard Tobin
    Replies:
    24
    Views:
    768
  5. fishfry

    Named parameters in method calls

    fishfry, Feb 6, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    90
    gnari
    Feb 9, 2004
Loading...

Share This Page