0
我在红宝石下面的哈希:搜索哈希
{
0 => {
:method=>\"POST \",
:path=>\"/api/online/platforms/fb/users/191023/add_infos\",
:host=>\"host.12\",
:duration=>\"1221\"
},
1 => {
:method=>\"GET \",
:path=>\"/api/customer/191023/messages\",
:host=>\"host.8\",
:duration=>\"99\"
},
2 => {
:method=>\"POST \",
:path=>\"/logs/data\",
:host=>\"host.10\",
:duration=>\"142\"
},
3 => {
:method=>\"POST \",
:path=>\"/api/customer/191023\",
:host=>\"host.6\",
:duration=>\"243\"
}
4 => {
:method=>\"POST \",
:path=>\"/api/customer/191023\",
:host=>\"host.2\",
:duration=>\"132\"
}
}
我愿做这些散列内一个简单的搜索,找到那些方法键设置为POST
和路径关键设置为"/api/customer/191023"
。相当于data.where(method: "POST", path: "/api/customer/191023")
。
首先,我试着只基于method
一个select
:
hs = hash.select{|k, h| h[:method] == "POST" }
但返回的哈希值是空的。
谢谢。
M.
确实我的不好,我以前的正则表达式产生的散列是错误的。谢谢 ! – Mich 2014-11-25 12:21:35
谢谢,但是什么是“v”变量?这是一个错字吗? – Mich 2014-11-25 14:07:36