Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. INDENT_STRING = " "
  2. def ph hash, indent = 0
  3. result = "{\n"
  4.  
  5. hash.sort_by{|e|e.inspect}.each do |key, value|
  6. result << INDENT_STRING * (indent+1)
  7. value = if Hash === value
  8. ph value, indent + 1
  9. else
  10. value.inspect
  11. end
  12. result << "#{key.inspect} => #{value}\n"
  13. end
  14.  
  15. result << INDENT_STRING * indent << "}"
  16.  
  17. if indent.zero?
  18. puts result
  19. else
  20. result
  21. end
  22. end
  23.  
  24. hash = {:a,4,6,"0x5QB527C",:o=,{:c,:q,:+,{:/,:-,:|,:&},:t,:A},:b,{:e,:d},:y,:x}
  25. ph hash
  26.  
  27. # >> {
  28. # >> 6 => "0x5QB527C"
  29. # >> :a => 4
  30. # >> :b => {
  31. # >> :e => :d
  32. # >> }
  33. # >> :o= => {
  34. # >> :+ => {
  35. # >> :/ => :-
  36. # >> :| => :&
  37. # >> }
  38. # >> :c => :q
  39. # >> :t => :A
  40. # >> }
  41. # >> :y => :x
  42. # >> }
Add Comment
Please, Sign In to add comment