Class: Hash
Constant Summary collapse
- KeyLengthMax =
30
Instance Method Summary collapse
Instance Method Details
#compatible?(other) ⇒ Boolean
37 38 39 40 41 |
# File 'lib/pretty_debug.rb', line 37 def compatible? other other.case?(Hash) and other.size == size and other.keys.all?{|k| key?(k)} end |
#inspect ⇒ Object
142 143 144 145 146 147 148 |
# File 'lib/pretty_debug.rb', line 142 def inspect keys = self.keys.map{|k| k.inspect.utf8} # When `self == empty?`, `...max` becomes `nil`. `to_i` turns it to `0`. w = keys.map(&:length).max.to_i.at_most(KeyLengthMax) [keys, values].parallel{|k, v| "#{k.ljust(w)} => #{v.inspect}"} .chain{|s| length < 2 ? "{#{s.join}}" : "{#$/#{s.join(",#$/").indent}#$/}"} end |