Skip to content

Instantly share code, notes, and snippets.

@sschimansky
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save sschimansky/15aa276001ed44a73f7b to your computer and use it in GitHub Desktop.

Select an option

Save sschimansky/15aa276001ed44a73f7b to your computer and use it in GitHub Desktop.
Hash#deep_underscore
class Hash
def deep_underscore(h = nil)
nh = {}
(h || self).each do |k,v|
nk = k.underscore
if v.is_a? Hash
puts "key #{k} recusive"
nh[nk] = deep_underscore v
elsif v.is_a? Array
nh[nk] = v.map do |eh|
deep_underscore eh
end
else
puts "key #{k} no - hash"
nh[nk] = v
end
h.delete v
end
nh
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment