将复杂哈希作为参数传递

时间:2013-07-27 18:45:24

标签: ruby hash

我想将这两个哈希作为参数传递给顶点方法,但Ruby不喜欢它。在每个哈希参数周围放置{}也不起作用。

vertex search_for_key: { id: '10' }, get_fields: { fullname: :full_name }

这样可行,但我想在一行:

search = {search_for_key: { id: '10' }}
fields = {get_fields: { fullname: :full_name }}

vertex search, fields

我错过了什么?

2 个答案:

答案 0 :(得分:2)

添加更多大括号和括号:

vertex({search_for_key: { id: '10' }}, {get_fields: { fullname: :full_name }})

答案 1 :(得分:2)

这是解决方案:

vertex({search_for_key: { id: '10' }}, {get_fields: { fullname: :full_name }})