Skip to content

Instantly share code, notes, and snippets.

@iamjwc
Created May 20, 2016 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamjwc/4bc4875ad8a91b9f3fe725f6f68f0167 to your computer and use it in GitHub Desktop.
Save iamjwc/4bc4875ad8a91b9f3fe725f6f68f0167 to your computer and use it in GitHub Desktop.
class Hash
def flarp(h = {}, prefix = nil)
each do |k, v|
new_k = [prefix, k].compact.join(".")
if v.is_a?(Array) || v.is_a?(Hash)
v.flarp(h, new_k)
else
h[new_k] = v
end
end
h
end
end
class Array
def flarp(h = {}, prefix = nil)
each_with_index do |v, i|
new_k = [prefix, i].compact.join(".")
if v.is_a?(Array) || v.is_a?(Hash)
v.flarp(h, new_k)
else
h[new_k] = v
end
end
h
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment