我有創造的紅寶石哈希出2門陣列(1.9.2)無力2個陣列組合成一個哈希 - 紅寶石
我的問題是一些哈希鍵的幾個問題是相同的,這似乎導致
所以我的第一個陣列(稱爲listkey)包含以下5項
puts listkey
service_monitor_errorlog
service_monitor_errorlog
wmt_errorlog
wmt_errorlog
syslog
第二(稱爲listvalue)包含以下5項
puts listvalue
service_monitor_errorlog.0
service_monitor_errorlog.current
wmt_errorlog.0
wmt_errorlog.current
syslog.txt
問題
我想要的是一個包含所有5個項目的散列,例如
{
"service_monitor_errorlog"=>"service_monitor_errorlog.0",
"service_monitor_errorlog"=>"service_monitor_errorlog.current",
"wmt_errorlog"=>"wmt_errorlog.0",
"wmt_errorlog"=>"wmt_errorlog.current",
"syslog"=>"syslog.txt"
}
但是使用散列zip命令
MyHash = Hash[listkey.zip(listvalue)]
我得到這個哈希生成
puts MyHash
{
"service_monitor_errorlog"=>"service_monitor_errorlog.current",
"wmt_errorlog"=>"wmt_errorlog.current",
"syslog"=>"syslog.txt"
}
誰能幫助?我已經試過各種命令到2個陣列合併成一個散列,但他們都不工作
乾杯
邁克
+++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++ +++
編輯
我剛剛發現了hashs必須有獨特的鍵,以便任何人都可以幫我找出一種方法來陣列組合,以形成與值陣列例如哈希
{
"service_monitor_errorlog"=>["service_monitor_errorlog.0", "service_monitor_errorlog.current"]
"wmt_errorlog"=> ["wmt_errorlog.0", "wmt_errorlog.current"]
"syslog"=> ["syslog.txt"]
}
你不能在哈希 – Bohdan 2012-01-05 12:50:34
網站注二等完全相同的鍵:使用「P」或「PP」或者「把OBJ 「檢查」來檢查對象,「提出」使它變得混亂。 – tokland 2012-01-05 13:22:54