2013-07-27 42 views
1

我想將這兩個散列作爲參數傳遞給頂點方法,但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

這是解決方案:

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

謝謝你的作品。我希望避免所有的句法噪音。有沒有更好的方法來解決這個問題,以保持代碼更清潔? – IUnknown

+0

@IUnknown不要把所有東西都放在一條線上。 –

2

添加更多的花括號,也括號:

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

將擴大到vertex有一個哈希作爲參數。這是與此相同:

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

既然你期望兩個參數爲vertex,這是行不通的。

+2

+1地說明了爲什麼什麼OP已經不起作用。但-1實際上沒有給出解決方案。但無論如何,足以達到解決方案,無論如何,我想+1也是如此。 –