This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# recursively compare the keys of these hashes, making sure that two has the same keys as one | |
one = {:id => 1, :items => [{:name => 'one'}, {:name => 'one:one'}]} | |
two = {:id => 2, :items => [{:name => 'two'}, {:name => 'two:two'}]} | |
def check_keys(hash1, hash2) | |
hash1.each_key do |key| | |
if hash1[key].is_a? Array | |
return hash1[key].each_index {|sub| check_keys(hash1[key][sub], hash2[key][sub])} if hash1[key].is_a? Hash | |
elsif hash1[key].is_a? Hash | |
return check_keys(hash1[key], hash2[key]) |