Skip to content

Commit b59ca2f

Browse files
tompnghsbt
authored andcommitted
Delay DidYouMean until NotFoundError#message is called
1 parent d0d4f46 commit b59ca2f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/rdoc/ri/driver.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class Error < RDoc::RI::Error; end
3434

3535
class NotFoundError < Error
3636

37-
def initialize(klass, suggestions = nil) # :nodoc:
37+
def initialize(klass, suggestion_proc = nil) # :nodoc:
3838
@klass = klass
39-
@suggestions = suggestions
39+
@suggestion_proc = suggestion_proc
4040
end
4141

4242
##
@@ -48,8 +48,9 @@ def name
4848

4949
def message # :nodoc:
5050
str = "Nothing known about #{@klass}"
51-
if @suggestions and !@suggestions.empty?
52-
str += "\nDid you mean? #{@suggestions.join("\n ")}"
51+
suggestions = @suggestion_proc&.call
52+
if suggestions and !suggestions.empty?
53+
str += "\nDid you mean? #{suggestions.join("\n ")}"
5354
end
5455
str
5556
end
@@ -948,8 +949,8 @@ def expand_class klass
948949
ary = class_names.grep(Regexp.new("\\A#{klass.gsub(/(?=::|\z)/, '[^:]*')}\\z"))
949950
if ary.length != 1 && ary.first != klass
950951
if check_did_you_mean
951-
suggestions = DidYouMean::SpellChecker.new(dictionary: class_names).correct(klass)
952-
raise NotFoundError.new(klass, suggestions)
952+
suggestion_proc = -> { DidYouMean::SpellChecker.new(dictionary: class_names).correct(klass) }
953+
raise NotFoundError.new(klass, suggestion_proc)
953954
else
954955
raise NotFoundError, klass
955956
end
@@ -1237,8 +1238,8 @@ def lookup_method name
12371238
methods.push(*store.instance_methods[klass]) if [:instance, :both].include? types
12381239
end
12391240
methods = methods.uniq
1240-
suggestions = DidYouMean::SpellChecker.new(dictionary: methods).correct(method_name)
1241-
raise NotFoundError.new(name, suggestions)
1241+
suggestion_proc = -> { DidYouMean::SpellChecker.new(dictionary: methods).correct(method_name) }
1242+
raise NotFoundError.new(name, suggestion_proc)
12421243
else
12431244
raise NotFoundError, name
12441245
end

0 commit comments

Comments
 (0)