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



91
92
93
94
95
96
97
# File 'lib/pretty_debug.rb', line 91

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

#ltsv(*args) ⇒ Object



129
130
131
132
133
134
# File 'lib/pretty_debug.rb', line 129

def ltsv *args
	if args.empty? then
		map{|k, v| "#{k}:#{v.to_s.tr("\t", " ")}"} else
		args.map{|k| "#{k}:#{self[k].to_s.tr("\t", " ")}"}
	end.join("\t")
end