Skip to content

Instantly share code, notes, and snippets.

@carlosveucv
Created September 1, 2016 14:50
Show Gist options
  • Save carlosveucv/b2add992606815a6a210026e82b0c730 to your computer and use it in GitHub Desktop.
Save carlosveucv/b2add992606815a6a210026e82b0c730 to your computer and use it in GitHub Desktop.
Compare 2 yaml's in ruby (print matching keys)
require 'yaml'
def compare_yaml_hash(cf1, cf2, context = [])
cf1.each do |key, value|
if cf2.key?(key)
puts "Contains key : #{key} in path #{context.join(".")}"
end
value2 = cf2[key]
next unless value2
if value.is_a?(Hash)
compare_yaml_hash(value, value2, (context + [key]))
next
end
end
end
f1 = ARGV[0]
f2 = ARGV[1]
compare_yaml_hash(YAML.load_file(f1), YAML.load_file(f2))
# Based on code posted on http://stackoverflow.com/questions/6274126/how-to-compare-keys-in-yaml-files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment