Skip to content

Instantly share code, notes, and snippets.

@andrewgross
Created July 15, 2013 14:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewgross/6000325 to your computer and use it in GitHub Desktop.
Save andrewgross/6000325 to your computer and use it in GitHub Desktop.
Helper functions for safely working with node attribute keys.
def has_nested_key?(key, hash)
hash = hash.to_hash
if has_indeterminate_key?(key, hash)
return true
end
hash.values.each do |v|
if v.is_a?(Hash) && has_nested_key?(key, v)
return true
end
end
return false
end
def self.has_indeterminate_key?(key, hash)
if hash.has_key?(key.to_s) || hash.has_key?(key.to_sym)
return true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment