naming parameters in the method calls

A

aidy

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
 
F

Farrel Lifson

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
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top