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



199
200
201
202
203
204
205
# File 'lib/pretty_debug.rb', line 199

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



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

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