Class: Array
Overview
Defined Under Namespace
Modules: PrettyInspect
Constant Summary
PrettyInspect::SingleLength
Instance Method Summary
collapse
#inspect
Instance Method Details
#align(ellipsis_limit = nil) ⇒ Object
296
297
298
299
300
301
302
303
304
|
# File 'lib/pretty_debug.rb', line 296
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 > max ? max : width)}
end.transpose
end
|
#common_affix ⇒ Object
first[0, (0…first.length).find{|i| first.! or others.any?{|s| first != s}}.to_i]
314
315
316
317
318
319
320
|
# File 'lib/pretty_debug.rb', line 314
def common_affix
each{|e| class_check(String, e){"All elements must be a String"}}
first, *others = self
i = - 1
i -= 1 while first[i] and others.all?{|s| first[i] == s[i]}
first[i + 1, -(i + 1)]
end
|
#common_prefix ⇒ Object
305
306
307
308
309
310
311
312
313
|
# File 'lib/pretty_debug.rb', line 305
def common_prefix
each{|e| class_check(String, e){"All elements must be a String"}}
first, *others = self
i = 0
i += 1 while first[i] and others.all?{|s| first[i] == s[i]}
first[0, i]
end
|