Skip to content
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

Merged
merged 1 commit into from
Sep 26, 2017

Conversation

ksss
Copy link
Contributor

@ksss ksss commented Sep 19, 2017

CRuby v2.5 will be able to call KeyError#receiver and KeyError#key.
I reimplement KeyNameChecker using it.

We'll be able to support suggesting Hash#fetch_values, Kernel#sprintf and ENV#[] also ;)

refs:

Copy link
Member

@yuki24 yuki24 left a 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 to lib/did_you_mean/spell_checkers
  • SPELL_CHECKERS["KeyError"] = KeyNameChecker should be moved to lib/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)
Copy link
Member

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
Copy link
Member

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.

@@ -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)
Copy link
Member

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.

@ksss
Copy link
Contributor Author

ksss commented Sep 26, 2017

Thank you for reviewing.
I fixed and rebased on this branch as a first-class feature 🎉

@yuki24
Copy link
Member

yuki24 commented Sep 26, 2017

Thanks!

@yuki24 yuki24 merged commit 6e93841 into ruby:master Sep 26, 2017
@ksss ksss deleted the key_error_2_5 branch September 27, 2017 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants