From 8a610e40f3cdb6f3f3b90f3ad34a469e1f25784f Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Mon, 7 Jan 2013 01:44:49 +0200 Subject: [PATCH] Code::LOC: add #== and use it in Code#== And fix a typo in comments. Signed-off-by: Kyrylo Silin --- lib/pry/code.rb | 8 +++----- lib/pry/code/loc.rb | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/pry/code.rb b/lib/pry/code.rb index d2a613ff..62cb2a2c 100644 --- a/lib/pry/code.rb +++ b/lib/pry/code.rb @@ -264,7 +264,7 @@ class Pry end end - # Format output with a marker next to the given +lineno+, unless +line_num+ + # Format output with a marker next to the given +lineno+, unless +lineno+ # is falsy. # # @param [Integer?] lineno @@ -357,10 +357,8 @@ class Pry # @return [Boolean] def ==(other) if other.is_a?(Code) - @other_lines = other.instance_variable_get(:@lines) - @lines.each_with_index.all? do |loc, i| - loc.line == @other_lines[i].line && loc.lineno == @other_lines[i].lineno - end + other_lines = other.instance_variable_get(:@lines) + @lines.each_with_index.all? { |loc, i| loc == other_lines[i] } else to_s.chomp == other.to_s.chomp end diff --git a/lib/pry/code/loc.rb b/lib/pry/code/loc.rb index 1ca73c52..b14bd1a6 100644 --- a/lib/pry/code/loc.rb +++ b/lib/pry/code/loc.rb @@ -28,6 +28,11 @@ class Pry @tuple = [line.chomp, lineno.to_i] end + # @return [Boolean] + def ==(other) + other.tuple == tuple + end + def dup self.class.new(line, lineno) end