Class: Hash

Inherits:
Object show all
Defined in:
lib/pretty_debug.rb

Constant Summary collapse

SingleLength =
50
KeyLengthMax =
30

Instance Method Summary collapse

Instance Method Details

#inspectObject



253
254
255
256
257
258
259
260
261
262
# File 'lib/pretty_debug.rb', line 253

def inspect
  return original_inspect if recursive?
  keys = self.keys.map(&:inspect)
  # 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(", ".freeze)}}" :  "{#$/#{s.join(",#$/".freeze).indent}#$/}"
end

#original_inspectObject



252
# File 'lib/pretty_debug.rb', line 252

alias original_inspect inspect