Class: Array

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

Instance Method Summary collapse

Instance Method Details

#align(ellipsis_limit = nil) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/pretty_debug.rb', line 151

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
=begin
  col_widths = transpose.map{|col| col.map{|cell| cell.to_s.length}.max}
  map{|row| [row, col_widths].transpose.map{|cell, l|
    max = ellipsis_limit || l
    l = l.at_most(max)
    case cell
    when Numeric then cell.to_s.ellipsis(max).rjust(l)
    else cell.to_s.ellipsis(max).ljust(l)
    end
  }.join(sep)}
=end

end

#compatible?(other) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/pretty_debug.rb', line 31

def compatible? other
  other.case?(Array) and
  other.length == length
end

#inspectObject



147
148
149
150
# File 'lib/pretty_debug.rb', line 147

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