您好我是ruby中的新手,我希望在键中输入带字符串的哈希值和值中的数组,如下所示:
Hash = new HashMap
for (issue :is)
Hash.add(is.user_name)
if(hash.contains(is.user_name)) then
hash.value.add(is)
end
end
得到这样的结果:
{"jane"[issue123,issue234,issue345]; "mike" [issue333,issue444,issue555]; "Alain" [issue876,issue987,issue356] }
jane有[issue123,issue234,issue345]
感谢
答案 0 :(得分:3)
如下所示:
result = Hash.new { |hash, key| hash[key] = [] }
issues.each do |issue|
result[issue.user_name].push issue
end