![](/img/trans.png)
[英]Is there a ruby or rails method that will return the hash key when checking for the hash key?
[英]Ruby Combine Hash Key As Hash + Key and return as array
假設我有一個哈希
雜湊= {“ 123” =>“ abc”,“ 124” =>“ def”}
我期待輸出
[[“” 123-abc“,” 123“],[” 124-def“,” 124“]],這樣我就可以將其傳遞給我的選擇標簽以顯示“ 123-abc”並在選擇時提交ID
我想出了一個解決方案
hash.map {| key,value | [“#{key}-#{value}”,鍵]}
但是還有其他更好的方法嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.