我想找出两个不同哈希之间的区别。
a = {"3"=>{"passenger_type"=>"ADT", "the_order"=>"3", "last"=>"ARUN", "first"=>"KUMAR", "middle"=>nil}, "2"=>{"passenger_type"=>"ADT", "the_order"=>"2", "last"=>"JONES", "first"=>"MAXIM", "middle"=>nil}, "1"=>{"passenger_type"=>"ADT", "the_order"=>"1", "last"=>"RAM", "first"=>"TODD", "middle"=>nil}}
b = {1=>{"middle"=>nil, "the_order"=>"1", "passenger_type"=>"BDT", "last"=>"RAM", "first"=>"TODD"}, 2=>{"middle"=>nil, "the_order"=>"2", "passenger_type"=>"ADT", "last"=>"JONES", "first"=>"MAXIM"}, 3=>{"middle"=>nil, "the_order"=>"3", "passenger_type"=>"ADT", "last"=>"ARUN", "first"=>"KUMAR"}}
生成的散列或数组应如下所示
{1=>{"middle"=>nil, "the_order"=>"1", "passenger_type"=>"BDT", "last"=>"RAM", "first"=>"TODD"}}
最佳答案
下面给出了答案,但不确定是否适合你的实际问题。您可能需要优化您的帖子,让其他人了解您的问题的详细信息。
b.select{|k, v| v != a[k.to_s]}
关于ruby - Ruby 中的深层嵌套哈希差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24198262/