@@ -34,9 +34,9 @@ class Error < RDoc::RI::Error; end
34
34
35
35
class NotFoundError < Error
36
36
37
- def initialize ( klass , suggestions = nil ) # :nodoc:
37
+ def initialize ( klass , suggestion_proc = nil ) # :nodoc:
38
38
@klass = klass
39
- @suggestions = suggestions
39
+ @suggestion_proc = suggestion_proc
40
40
end
41
41
42
42
##
@@ -48,8 +48,9 @@ def name
48
48
49
49
def message # :nodoc:
50
50
str = "Nothing known about #{ @klass } "
51
- if @suggestions and !@suggestions . empty?
52
- str += "\n Did you mean? #{ @suggestions . join ( "\n " ) } "
51
+ suggestions = @suggestion_proc &.call
52
+ if suggestions and !suggestions . empty?
53
+ str += "\n Did you mean? #{ suggestions . join ( "\n " ) } "
53
54
end
54
55
str
55
56
end
@@ -948,8 +949,8 @@ def expand_class klass
948
949
ary = class_names . grep ( Regexp . new ( "\\ A#{ klass . gsub ( /(?=::|\z )/ , '[^:]*' ) } \\ z" ) )
949
950
if ary . length != 1 && ary . first != klass
950
951
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 )
953
954
else
954
955
raise NotFoundError , klass
955
956
end
@@ -1237,8 +1238,8 @@ def lookup_method name
1237
1238
methods . push ( *store . instance_methods [ klass ] ) if [ :instance , :both ] . include? types
1238
1239
end
1239
1240
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 )
1242
1243
else
1243
1244
raise NotFoundError , name
1244
1245
end
0 commit comments