refactored add_line_numbers to use colorize method
This commit is contained in:
parent
6d42e46d85
commit
3c6f8ecc9c
|
@ -23,15 +23,16 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
def colorize text
|
||||
Pry.color ? CodeRay.scan(text.to_s, :ruby).term : text
|
||||
end
|
||||
|
||||
def add_line_numbers(lines, start_line)
|
||||
line_array = lines.each_line.to_a
|
||||
line_array.each_with_index.map do |line, idx|
|
||||
adjusted_index = idx + start_line
|
||||
"#{colorize adjusted_index}: #{line}"
|
||||
if Pry.color
|
||||
cindex = CodeRay.scan("#{adjusted_index}", :ruby).term
|
||||
"#{cindex}: #{line}"
|
||||
else
|
||||
"#{idx}: #{line}"
|
||||
end
|
||||
end.join
|
||||
end
|
||||
|
||||
|
@ -66,19 +67,6 @@ class Pry
|
|||
end
|
||||
end
|
||||
|
||||
def remove_first_word(text)
|
||||
text.split.drop(1).join(' ')
|
||||
end
|
||||
|
||||
# turn off color for duration of block
|
||||
def no_color(&block)
|
||||
old_color_state = Pry.color
|
||||
Pry.color = false
|
||||
yield
|
||||
ensure
|
||||
Pry.color = old_color_state
|
||||
end
|
||||
|
||||
def code_and_code_type_for(meth)
|
||||
case code_type = code_type_for(meth)
|
||||
when nil
|
||||
|
|
Loading…
Reference in New Issue