我的代码就是这个
@logs= {-1=>{""=>{:source=>1, :time=>0, :skipped=>0, :mysql=>0, :es=>1}}}
@logs.each_pair { |user_id , user_content|
user_content.each_pair { |kwd , ser_content.each_pair { |kwd , kwd_content|
h=kwd_content
}}
h={:time_taken=>0, :skipped_count=>0, :mysql_count=>0, :es_count=>1, :source_count=>1}
这需要花费很多时间 请帮帮我
答案 0 :(得分:0)
如果您要查找的是总计哈希值的哈希值:
@logs = {-1=>{""=>{:source=>1, :time=>0, :skipped=>0, :mysql=>0, :es=>1}}, -2=>{""=>{:source=>1, :time=>0, :skipped=>0, :mysql=>0, :es=>1}}}
# last part is from http://stackoverflow.com/a/4453690/178651
h = @logs.values.map{|i|i.values}.flatten.inject{|memo, el| memo.merge( el ){|k, old_v, new_v| old_v + new_v}}
将导致h:
的以下值=> {:source=>2, :time=>0, :skipped=>0, :mysql=>0, :es=>2}