Created
July 15, 2013 14:20
-
-
Save andrewgross/6000325 to your computer and use it in GitHub Desktop.
Helper functions for safely working with node attribute keys.
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
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