Ruby中的深层嵌套哈希差异

Ruby中的深层嵌套哈希差异,ruby,associative-array,Ruby,Associative Array,我想找出两个不同散列之间的差异 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"=>

我想找出两个不同散列之间的差异

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]}

非常感谢您@Arie Shaw。我尝试了一些复杂的逻辑,但你只用了一行就做到了。我看到这一行很漂亮,不禁哭了起来,想到了PHP中的
array\u udiff()
,以及完成同样任务所需的几十行代码。