Module: Hash::PrettyInspect
- Included in:
- Hash
- Defined in:
- lib/pretty_debug.rb
Constant Summary collapse
- SingleLength =
50- KeyLengthMax =
30
Instance Method Summary collapse
Instance Method Details
#inspect ⇒ Object
258 259 260 261 262 263 264 265 266 267 |
# File 'lib/pretty_debug.rb', line 258 def inspect return super if recursive? keys = keys().map(&:inspect) #Purpose# When `self == empty?`, `...max` becomes `nil`. `to_i` turns it to `0`. w = keys.map(&:length).max.to_i w = w > KeyLengthMax ? KeyLengthMax : w s = [keys, values].transpose.map{|k, v| "#{k.ljust(w)} => #{v.inspect}"} length < 2 || s.map(&:length).inject(:+) < SingleLength ? "{#{s.join(", ")}}" : "{#$/#{s.join(",#$/").indent}#$/}" end |