Skip to content

Instantly share code, notes, and snippets.

@Mikoangelo
Created August 9, 2008 18:52
Show Gist options
  • Save Mikoangelo/4701 to your computer and use it in GitHub Desktop.
Save Mikoangelo/4701 to your computer and use it in GitHub Desktop.
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