Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
试图理解ruby Webdriver.for方法_Ruby_Selenium - Fatal编程技术网

试图理解ruby Webdriver.for方法

试图理解ruby Webdriver.for方法,ruby,selenium,Ruby,Selenium,我刚接触Selenium for Ruby,我只是想了解一些语法。我知道webdriver.for使用的是第一个参数“firefox”,但我不明白为什么逗号后面会有散列。这是“for”方法的另一个论点吗?我查阅了api文档,它显示“for”方法只接受一个参数,所以我不确定另一个参数是什么 这是“for”方法的另一个论点吗 是的,在ruby中,如果散列参数是参数列表中的最后一个参数,则不必编写大括号。下面是您可能看到的不同语法的示例: WebDriver.for :firefox, :profil

我刚接触Selenium for Ruby,我只是想了解一些语法。我知道webdriver.for使用的是第一个参数“firefox”,但我不明白为什么逗号后面会有散列。这是“for”方法的另一个论点吗?我查阅了api文档,它显示“for”方法只接受一个参数,所以我不确定另一个参数是什么

这是“for”方法的另一个论点吗

是的,在ruby中,如果散列参数是参数列表中的最后一个参数,则不必编写大括号。下面是您可能看到的不同语法的示例:

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

您的代码指定的散列参数只有一个键/值对。

非常感谢您的回答!我绞尽脑汁想弄明白。
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}