David Q
David Q

Reputation: 196

Trying to understand the ruby Webdriver.for method

WebDriver.for :firefox, :profile => "some-profile"

I'm new to Selenium for Ruby and i'm just trying to understand some syntax. I understand that the webdriver.for is using the first argument "firefox", but I don't understand why there is hash after the comma. Is that another argument going into the "for" method? I looked up the api docs and it shows that the "for" method only takes one argument, so I'm not exactly sure what the other argument is.

Upvotes: 1

Views: 53

Answers (1)

7stud
7stud

Reputation: 48649

Is that another argument going into the "for" method?

Yes, in ruby if a hash argument is the last argument in the list of arguments, you don't have to write the braces. Here is an example of the different syntaxes you might see:

def do_stuff(x, y, hash)
  p hash
end


do_stuff(10, 20, {:a => 30, :b => 40})
do_stuff(10, 20, :a=>30, :b=>40)
do_stuff 10, 20, :a=>30, :b=>40
do_stuff 10, 20, a:30, b:40


--output:--
{:a=>30, :b=>40}
{:a=>30, :b=>40}
{:a=>30, :b=>40}
{:a=>30, :b=>40}

Your code specifies a hash argument with only one key/value pair.

Upvotes: 1

Related Questions