Skip to content

Instantly share code, notes, and snippets.

@captainpete
Created May 25, 2011 01:51
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 captainpete/990168 to your computer and use it in GitHub Desktop.
Save captainpete/990168 to your computer and use it in GitHub Desktop.
Sample Hash unwrapper for Jon
def unwrap_hash(hash, scope = [])
hash.each do |key, value|
scope.push key
if value.is_a? Hash
unwrap_hash value, scope
else
puts "#{scope.join(':')} = #{value.inspect}"
end
scope.pop
end
end
unwrap_hash({
:one => {
:apple => 1,
:pears => 14
},
:rabbit => {
:moonshine => 84,
:overture => 'Concerto number 4'
}
})
# one:apple = 1
# one:pears = 14
# rabbit:overture = "Concerto number 4"
# rabbit:moonshine = 84
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment