diff --git a/lib/pry/default_commands/shell.rb b/lib/pry/default_commands/shell.rb index 3be73f8d..3a629b48 100644 --- a/lib/pry/default_commands/shell.rb +++ b/lib/pry/default_commands/shell.rb @@ -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 diff --git a/lib/pry/helpers/command_helpers.rb b/lib/pry/helpers/command_helpers.rb index afe5f8ed..bae11f49 100644 --- a/lib/pry/helpers/command_helpers.rb +++ b/lib/pry/helpers/command_helpers.rb @@ -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