Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.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 将散列作为参数传递_Ruby - Fatal编程技术网

Ruby 将散列作为参数传递

Ruby 将散列作为参数传递,ruby,Ruby,我有两个哈希: deploy = {} config[:mysql] = {} 我还有一个这样的功能: def some_cool_function(mysql_config) { foo:bar } end 调用函数并将结果分配给哈希时,如下所示: deploy.mysql = some_cool_function(config.mysql) 我为# hashmysql可能只是不存在于confighash中,但我还没有研究这个选项 但我觉得这是对的,我是不是做错了什么?

我有两个哈希:

deploy = {}
config[:mysql] = {}
我还有一个这样的功能:

def some_cool_function(mysql_config)
  {
     foo:bar
  }
end
调用函数并将结果分配给哈希时,如下所示:

deploy.mysql = some_cool_function(config.mysql)
我为#

hash
mysql
可能只是不存在于
config
hash中,但我还没有研究这个选项


但我觉得这是对的,我是不是做错了什么?我对ruby语言相当陌生。

Hash
es不像
JSON
。散列访问器方法是
[](val)
fetch(val)
,因此在您的情况下
config.mysql
应该是
config[:mysql]
config.fetch(:mysql)
@enginersmnky完美谢谢。