Skip to content

Instantly share code, notes, and snippets.

@panbanda
Created April 10, 2015 13:49
Show Gist options
  • Save panbanda/815bbbe2ad9e35b613e6 to your computer and use it in GitHub Desktop.
Save panbanda/815bbbe2ad9e35b613e6 to your computer and use it in GitHub Desktop.
Flatten Hash Ruby on Rails
def flatten_hash hash
hash.each_with_object({}) do |(k, v), h|
if v.is_a? Hash
flatten_hash(v).map do |h_k, h_v|
h["#{h_k}"] = h_v
end
else
h[k] = v
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment