Method: Pry::Helpers::Text#with_line_numbers

Defined in:
lib/pry/helpers/text.rb

#with_line_numbers(text, offset, color = :blue) ⇒ String

Returns text in a numbered list, beginning at offset.

Parameters:

  • text (#each_line)
  • offset (Fixnum)

Returns:

  • (String)


100
101
102
103
104
105
106
107
# File 'lib/pry/helpers/text.rb', line 100

def with_line_numbers(text, offset, color = :blue)
  lines = text.each_line.to_a
  max_width = (offset + lines.count).to_s.length
  lines.each_with_index.map do |line, index|
    adjusted_index = (index + offset).to_s.rjust(max_width)
    "#{send(color, adjusted_index)}: #{line}"
  end.join
end