Class: Array
Overview
String Formatting
Direct Known Subclasses
Constant Summary collapse
- SingleLength =
50
Instance Method Summary collapse
- #align(ellipsis_limit = nil) ⇒ Object
- #common_affix ⇒ Object
- #common_prefix ⇒ Object
- #inspect ⇒ Object
Instance Method Details
#align(ellipsis_limit = nil) ⇒ Object
235 236 237 238 239 240 241 242 |
# File 'lib/pretty_debug.rb', line 235 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
250 251 252 253 254 255 256 |
# File 'lib/pretty_debug.rb', line 250 def common_affix each{|e| class_check(e, String){"All elements must be a String".freeze}} 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_prefix ⇒ Object
243 244 245 246 247 248 249 |
# File 'lib/pretty_debug.rb', line 243 def common_prefix each{|e| class_check(e, String){"All elements must be a String".freeze}} first, *others = self i = 0 loop{break unless first[i] and others.all?{|s| first[i] == s[i]}; i += 1} first[0, i] end |
#inspect ⇒ Object
185 186 187 188 189 |
# File 'lib/pretty_debug.rb', line 185 def inspect s = map(&:inspect) length < 2 || s.map(&:length).inject(:+) < SingleLength ? "[#{s.join(", ".freeze)}]" : "[#$/#{s.join(",#$/".freeze).indent}#$/]" end |