Created
June 10, 2012 06:05
-
-
Save dotmh/2904078 to your computer and use it in GitHub Desktop.
A ruby hash inspector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def inspect data , depth = 0 | |
data.each do | key , value | | |
if value.class == Hash | |
spacing = '' | |
depth.times { spacing << '-' } | |
puts spacing+' '+key.to_s | |
inspect value , depth+1 | |
else | |
spacing = '' | |
depth.times { spacing << '-' } | |
puts spacing+' '+key.to_s+': '+value.to_s | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ok this isn't actual that useful as it can only inspect Hashes , I am writing a new one that is able to do more.
PS if I am been stupid and there is a nice way to output hashes natively in ruby then let me know.