diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb index 07788482..266db281 100644 --- a/lib/pry/wrapped_module.rb +++ b/lib/pry/wrapped_module.rb @@ -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>] The array of `Pry::Method` objects,