summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2020-03-20 19:52:23 +0800
committerGitHub <noreply@github.com>2020-03-20 19:52:23 +0800
commitdc6ce461bb03453fc850b7800ae6e68dadad3c1e (patch)
treec5a68c63acec6e1ce5a1b1f614dc9b021421eb51
parent68ee107c58d3f65575a1a1fa26c014b16286b888 (diff)
parent0080384b6b3f7838e59a1fcb8c9828556ed379ab (diff)
downloadpry-dc6ce461bb03453fc850b7800ae6e68dadad3c1e.tar.gz
Merge pull request #2098 from barrettkingram/whereami_bug_fix
Fix whereami -c bug when class definition is not beginning of line
-rw-r--r--lib/pry/wrapped_module/candidate.rb2
-rw-r--r--spec/commands/whereami_spec.rb11
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/pry/wrapped_module/candidate.rb b/lib/pry/wrapped_module/candidate.rb
index 509b75bc..f48f8751 100644
--- a/lib/pry/wrapped_module/candidate.rb
+++ b/lib/pry/wrapped_module/candidate.rb
@@ -103,7 +103,7 @@ class Pry
def class_regexes
mod_type_string = wrapped.class.to_s.downcase
- [/^\s*#{mod_type_string}\s+(?:(?:\w*)::)*?#{wrapped.name.split(/::/).last}/,
+ [/(^|=)\s*#{mod_type_string}\s+(?:(?:\w*)::)*?#{wrapped.name.split(/::/).last}/,
/^\s*(::)?#{wrapped.name.split(/::/).last}\s*?=\s*?#{wrapped.class}/,
/^\s*(::)?#{wrapped.name.split(/::/).last}\.(class|instance)_eval/]
end
diff --git a/spec/commands/whereami_spec.rb b/spec/commands/whereami_spec.rb
index cf674091..fd351d0f 100644
--- a/spec/commands/whereami_spec.rb
+++ b/spec/commands/whereami_spec.rb
@@ -218,6 +218,17 @@ describe "whereami" do
end
Object.remove_const(:Cor)
end
+
+ it 'should show class when -c option used, and beginning of the class is on the' \
+ 'same line as another expression' do
+ out = class Cor
+ def blimey; end
+ pry_eval(binding, 'whereami -c')
+ end
+ expect(out).to match(/class Cor/)
+ expect(out).to match(/blimey/)
+ Object.remove_const(:Cor)
+ end
end
it 'should not show line numbers or marker when -n switch is used' do