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
|
@ -302,11 +302,15 @@ class Pry
|
|||
|
||||
# @return [Pry::WrappedModule::Candidate] The candidate with the
|
||||
# highest rank, that is the 'monkey patch' of this module with the
|
||||
# highest number of methods, which actually contains a source code
|
||||
# line that declaes the module. It is considered the 'canonical'
|
||||
# definition for the module.
|
||||
# highest number of methods, which contains a source code line that
|
||||
# defines the module. It is considered the 'canonical' definition
|
||||
# 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
|
||||
@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
|
||||
|
||||
# @return [Array<Array<Pry::Method>>] The array of `Pry::Method` objects,
|
||||
|
|
Loading…
Reference in New Issue