1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

moved restrict_to_lines to command_helpers.rb

This commit is contained in:
John Mair 2012-01-23 21:12:00 +13:00
parent 59f72522d8
commit 06e4dedabb
2 changed files with 9 additions and 5 deletions

View file

@ -100,11 +100,6 @@ class Pry
"w"
end
end
def restrict_to_lines(content, lines)
line_range = one_index_range(lines)
content.lines.to_a[line_range].join
end
end
create_command "cat", "Show code from a file, Pry's input buffer, or the last exception." do

View file

@ -191,6 +191,15 @@ class Pry
text.gsub(/^#{margin}/, '')
end
# Restrict a string to the given range of lines (1-indexed)
# @param [String] content The string.
# @param [Range, Fixnum] lines The line(s) to restrict it to.
# @return [String] The resulting string.
def restrict_to_lines(content, lines)
line_range = one_index_range_or_number(lines)
Array(content.lines.to_a[line_range]).join
end
def one_index_number(line_number)
if line_number > 0
line_number - 1