Created
August 9, 2008 18:52
-
-
Save Mikoangelo/4701 to your computer and use it in GitHub Desktop.
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
INDENT_STRING = " " | |
def ph hash, indent = 0 | |
result = "{\n" | |
hash.sort_by{|e|e.inspect}.each do |key, value| | |
result << INDENT_STRING * (indent+1) | |
value = if Hash === value | |
ph value, indent + 1 | |
else | |
value.inspect | |
end | |
result << "#{key.inspect} => #{value}\n" | |
end | |
result << INDENT_STRING * indent << "}" | |
if indent.zero? | |
puts result | |
else | |
result | |
end | |
end | |
hash = {:a,4,6,"0x5QB527C",:o=,{:c,:q,:+,{:/,:-,:|,:&},:t,:A},:b,{:e,:d},:y,:x} | |
ph hash | |
# >> { | |
# >> 6 => "0x5QB527C" | |
# >> :a => 4 | |
# >> :b => { | |
# >> :e => :d | |
# >> } | |
# >> :o= => { | |
# >> :+ => { | |
# >> :/ => :- | |
# >> :| => :& | |
# >> } | |
# >> :c => :q | |
# >> :t => :A | |
# >> } | |
# >> :y => :x | |
# >> } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment