diff options
author | Barrett Ingram <bingram@eab.com> | 2019-12-29 21:49:56 -0600 |
---|---|---|
committer | Barrett Ingram <bingram@eab.com> | 2019-12-29 22:20:34 -0600 |
commit | 0080384b6b3f7838e59a1fcb8c9828556ed379ab (patch) | |
tree | 644b178f031a806a733f5ccafdf9abecf527b7dd | |
parent | 62c8951374aeed5a7423609a108848b0bcf81685 (diff) | |
download | pry-0080384b6b3f7838e59a1fcb8c9828556ed379ab.tar.gz |
Fix whereami -c when class definition is not beginning of line
Consider the following class definition:
```
out = class Cor
def blimey; end
pry_eval(binding, 'whereami -c')
end
```
For classes defined as part of an expression like this, "whereami -c"
was failing to find the class definition. To fix this, we modify the
regular expression so the "class" keyword is no longer required to
appear at the beginning of the line IF there is an equals sign preceding
it.
https://github.com/pry/pry/issues/2052
-rw-r--r-- | lib/pry/wrapped_module/candidate.rb | 2 | ||||
-rw-r--r-- | spec/commands/whereami_spec.rb | 11 |
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 |