我有两个哈希数组是这样的:比较红宝石两个哈希阵列,除了一键
hashArray1 = [{"id"=>"1","data"=>"data1"},{"id"=>"2","data"=>"data2"}]
hashArray2 = [{"id"=>"3","data"=>"data1"},{"id"=>"4","data"=>"data2"}]
我想比较两者,如果一切没有“ID”键匹配返回true。
我已经试过这样的事情:
hashArray1.each do |h1|
hashArray2.each do |h2|
if h1.select{|h| h!= "id"} == h2.select{|b| b!= "id"}
break
else
return false
end
end
end
但这似乎是不正确的。有没有人有更好的解决方案。我在1.9.3平原红宝石,不使用rails框架。
您的变量名称'hash1'和'hash2'具有误导性。他们不是哈希。 – sawa
@sawa点指出,现在希望它罚款。但这个问题已经得到解答。 –