Permalink
Browse files

Break up `Pry::Code#between`

Signed-off-by: Kyrylo Silin <kyrylosilin@gmail.com>
  • Loading branch information...
1 parent f3a6242 commit eb7ada1e90f7cf706f90c89fea244bd558c8a24f @kyrylo kyrylo committed Jan 3, 2013
Showing with 12 additions and 11 deletions.
  1. +12 −11 lib/pry/code.rb
View
@@ -180,17 +180,8 @@ def between(start_line, end_line=nil)
end_line ||= start_line
end
- if start_line > 0
- start_idx = @lines.index { |l| l.last >= start_line } || @lines.length
- else
- start_idx = start_line
- end
-
- if end_line > 0
- end_idx = (@lines.index { |l| l.last > end_line } || 0) - 1
- else
- end_idx = end_line
- end
+ start_idx = find_start_index(start_line)
+ end_idx = find_end_index(end_line)
alter do
@lines = @lines[start_idx..end_idx] || []
@@ -410,5 +401,15 @@ def add_marker(line_tuple)
def add_indentation(line_tuple)
line_tuple[0] = "#{ ' ' * @indentation_num }#{ line_tuple[0] }"
end
+
+ def find_start_index(start_line)
+ return start_line if start_line < 0
+ @lines.index { |l| l.last >= start_line } || @lines.length
+ end
+
+ def find_end_index(end_line)
+ return end_line if end_line < 0
+ (@lines.index { |l| l.last > end_line } || 0) - 1
+ end
end
end

0 comments on commit eb7ada1

Please sign in to comment.