Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/rdoc/ri/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class Error < RDoc::RI::Error; end

class NotFoundError < Error

def initialize(klass, suggestions = nil) # :nodoc:
def initialize(klass, suggestion_proc = nil) # :nodoc:
@klass = klass
@suggestions = suggestions
@suggestion_proc = suggestion_proc
end

##
Expand All @@ -48,8 +48,9 @@ def name

def message # :nodoc:
str = "Nothing known about #{@klass}"
if @suggestions and !@suggestions.empty?
str += "\nDid you mean? #{@suggestions.join("\n ")}"
suggestions = @suggestion_proc&.call
if suggestions and !suggestions.empty?
str += "\nDid you mean? #{suggestions.join("\n ")}"
end
str
end
Expand Down Expand Up @@ -948,8 +949,8 @@ def expand_class klass
ary = class_names.grep(Regexp.new("\\A#{klass.gsub(/(?=::|\z)/, '[^:]*')}\\z"))
if ary.length != 1 && ary.first != klass
if check_did_you_mean
suggestions = DidYouMean::SpellChecker.new(dictionary: class_names).correct(klass)
raise NotFoundError.new(klass, suggestions)
suggestion_proc = -> { DidYouMean::SpellChecker.new(dictionary: class_names).correct(klass) }
raise NotFoundError.new(klass, suggestion_proc)
else
raise NotFoundError, klass
end
Expand Down Expand Up @@ -1237,8 +1238,8 @@ def lookup_method name
methods.push(*store.instance_methods[klass]) if [:instance, :both].include? types
end
methods = methods.uniq
suggestions = DidYouMean::SpellChecker.new(dictionary: methods).correct(method_name)
raise NotFoundError.new(name, suggestions)
suggestion_proc = -> { DidYouMean::SpellChecker.new(dictionary: methods).correct(method_name) }
raise NotFoundError.new(name, suggestion_proc)
else
raise NotFoundError, name
end
Expand Down