diff options
author | tompng <[email protected]> | 2023-09-12 02:53:23 +0900 |
---|---|---|
committer | git <[email protected]> | 2023-10-17 11:07:57 +0000 |
commit | 2a8ac8ead5d4deb4fcef8f3c13c521eded2301c4 (patch) | |
tree | 65b3e6abd4ebf9be6e0fcf5317df4b7bfa6ff276 | |
parent | 7362c484c8e5bdf9e05ac5dd10c23162a8e117ad (diff) |
[ruby/rdoc] Delay DidYouMean until NotFoundError#message is called
https://github.com/ruby/rdoc/commit/b59ca2f981
-rw-r--r-- | lib/rdoc/ri/driver.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb index 819cff8aa3..08c4d08f81 100644 --- a/lib/rdoc/ri/driver.rb +++ b/lib/rdoc/ri/driver.rb @@ -34,9 +34,9 @@ class RDoc::RI::Driver 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 ## @@ -48,8 +48,9 @@ class RDoc::RI::Driver def message # :nodoc: str = "Nothing known about #{@klass}" - if @suggestions and [email protected]? - 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 @@ -948,8 +949,8 @@ or the PAGER environment variable. 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 @@ -1237,8 +1238,8 @@ or the PAGER environment variable. 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 |