Class: Array

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

Overview

Terminal

Direct Known Subclasses

PrettyArray

Constant Summary collapse

SingleLength =
50

Instance Method Summary collapse

Instance Method Details

#align(ellipsis_limit = nil) ⇒ Object



207
208
209
210
211
212
213
214
# File 'lib/pretty_debug.rb', line 207

def align ellipsis_limit = nil
	transpose.map do |col|
		just = case col.first; when Numeric then :rjust; else :ljust end
		width = col.map{|cell| cell.to_s.length}.max
		max = ellipsis_limit || width
		col.map{|cell| cell.to_s.ellipsis(max).send(just, width.at_most(max))}
	end.transpose
end

#common_affixObject

Raises:

  • (ArgumentError)


222
223
224
225
226
227
228
# File 'lib/pretty_debug.rb', line 222

def common_affix
	raise ArgumentError.new("All elements must be a String") unless all?{|e| e.kind_of?(String)}
	first, *others = self
	i = - 1
	loop{break unless first[i] and others.all?{|s| first[i] == s[i]}; i -= 1}
	first[i + 1, -(i + 1)]
end

#common_prefixObject

Raises:

  • (ArgumentError)


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

def common_prefix
	raise ArgumentError.new("All elements must be a String") unless all?{|e| e.kind_of?(String)}
	first, *others = self
	i = 0
	loop{break unless first[i] and others.all?{|s| first[i] == s[i]}; i += 1}
	first[0, i]
end

#inspectObject



202
203
204
205
206
# File 'lib/pretty_debug.rb', line 202

def inspect
	map(&:inspect)
	.chain{|s| length < 2 || s.map(&:length).inject(:+) < SingleLength ?
		"[#{s.join(", ")}]" : "[#$/#{s.join(",#$/").indent}#$/]"}
end