mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Avoid returning nil in #primary_candidate
When there is no suitable candidate, instead of memoizing and returning a nil value, the #primary_candidate method should still return the rank 0 candidate, or raise an error.
This commit is contained in:
parent
5342a65197
commit
ec1a3c5bc4
1 changed files with 8 additions and 4 deletions
|
@ -302,11 +302,15 @@ class Pry
|
||||||
|
|
||||||
# @return [Pry::WrappedModule::Candidate] The candidate with the
|
# @return [Pry::WrappedModule::Candidate] The candidate with the
|
||||||
# highest rank, that is the 'monkey patch' of this module with the
|
# highest rank, that is the 'monkey patch' of this module with the
|
||||||
# highest number of methods, which actually contains a source code
|
# highest number of methods, which contains a source code line that
|
||||||
# line that declaes the module. It is considered the 'canonical'
|
# defines the module. It is considered the 'canonical' definition
|
||||||
# definition for the module.
|
# for the module. In the absense of a suitable candidate, the
|
||||||
|
# candidate of rank 0 will be returned, or a CommandError raised if
|
||||||
|
# there are no candidates at all.
|
||||||
def primary_candidate
|
def primary_candidate
|
||||||
@primary_candidate ||= candidates.find { |c| c.file }
|
@primary_candidate ||= candidates.find { |c| c.file } ||
|
||||||
|
# This will raise an exception if there is no candidate at all.
|
||||||
|
candidate(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Array<Array<Pry::Method>>] The array of `Pry::Method` objects,
|
# @return [Array<Array<Pry::Method>>] The array of `Pry::Method` objects,
|
||||||
|
|
Loading…
Reference in a new issue