Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Finds keys in a hash that are not strings
def detect_bad_keys(obj, parent_path)
result = []
case obj
when Hash
obj.each do |key, value|
if key.is_a?(String)
result.concat(detect_bad_keys(value, [*parent_path, key]))
else
result.push([*parent_path, key])
end
end
when Array
obj.each_with_index do |value, key|
result.concat(detect_bad_keys(value, [*parent_path, key]))
end
end
result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment