-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ReImplement KeyNameChecker using CRuby's new API #91
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to promote this to a first-class feature as it is no longer necessary to monkey-patch the Hash
class.
KeyNameChecker
should be moved tolib/did_you_mean/spell_checkers
SPELL_CHECKERS["KeyError"] = KeyNameChecker
should be moved tolib/did_you_mean.rb
@@ -1,31 +1,43 @@ | |||
module DidYouMean | |||
module Experimental | |||
module KeyErrorWithNameAndKeys | |||
FILE_REGEXP = %r"#{Regexp.quote(__FILE__)}" | |||
if KeyError.method_defined?(:receiver) && KeyError.method_defined?(:key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to worry about backward-compatibility since GH master is only compatible with the latest Ruby (2.5.0-dev
at the time of writing).
end | ||
Hash.prepend KeyErrorWithNameAndKeys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module could be removed entirely.
test/experimental/key_error_test.rb
Outdated
@@ -12,4 +12,37 @@ def test_corrects_hash_key_name | |||
assert_correction %("foo"), error.corrections | |||
assert_match %(Did you mean? "foo"), error.to_s | |||
end | |||
|
|||
if KeyError.method_defined?(:receiver) && KeyError.method_defined?(:key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could always run these tests since Ruby 2.5.0 (and later) is the only version DYM 1.2.0 is going to be compatible with.
Thank you for reviewing. |
Thanks! |
CRuby v2.5 will be able to call
KeyError#receiver
andKeyError#key
.I reimplement
KeyNameChecker
using it.We'll be able to support suggesting
Hash#fetch_values
,Kernel#sprintf
andENV#[]
also ;)refs:
KeyError
checker #71