Class: Hash

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

Overview

LTSV

Constant Summary collapse

KeyLengthMax =
30

Instance Method Summary collapse

Instance Method Details

#inspectObject



215
216
217
218
219
220
221
# File 'lib/pretty_debug.rb', line 215

def inspect
  keys = self.keys.map(&:inspect)
  # When `self == empty?`, `...max` becomes `nil`. `to_i` turns it to `0`.
  w = keys.map(&:length).max.to_i.at_most(KeyLengthMax)
  [keys, values].transpose.map{|k, v| "#{k.ljust(w)} => #{v.inspect}"}
  .chain{|s| length < 2 ? "{#{s.join}}" :  "{#$/#{s.join(",#$/").indent}#$/}"}
end

#ltsvObject



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

def ltsv; map{|k, v| "#{k}:#{v.to_s.tr("\t", " ")}"}.join("\t") end