-
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
Implement KeyError
checker
#71
Conversation
module Correctable | ||
prepend_features KeyError | ||
end | ||
end |
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 prefer the following over #prepend_features
:
KeyError.prepend DidYouMean::Correctable
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.
Sounds cool
Thank you for your kind reply. |
end | ||
Hash.prepend KeyErrorReciver | ||
|
||
class KeyNameChecker < MethodNameChecker |
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 don't think it makes sense to let KeyNameChecker
inherit from MethodNameChecker
since KeyError
doesn't behave like NameError
. It can just include SpellCheckable
and implement what is needed.
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 misunderstood about "abstracted away".
I'll implement KeyNameChecker
again.
I rebased again. |
klass.send(:attr, :keys, :name) | ||
end | ||
end | ||
KeyError.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.
We don't need a module then.
KeyError.send(:attr, :name, :keys)
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.
Right.
I have a question. Can we remove this library backtrace? test.rb #! /usr/bin/env ruby
require 'did_you_mean'
require 'did_you_mean/extra_features'
{foo: 1}.fetch(:ffo) expect
actual
|
I think really good pull request. test.rb #! /usr/bin/env ruby
require 'did_you_mean'
require 'did_you_mean/extra_features'
{foo: 1}.fetch_values(:ffo) expect
actual
|
I think need core help to support all methods that raise KeyError. |
Thank you for answer 😄 |
I have solved the problem that remove self file backtrace at ksss@7314d4e . |
|
||
error = assert_raises(KeyError) { hash.fetch("fooo") } | ||
assert_correction %("foo"), error.corrections | ||
assert_match %(Did you mean? "foo"), error.to_s |
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.
would be interesting to say Did you mean? :foo
(the symbol) when "foo"
(the string) is passed.
@ksss I'll merge this pull request once it's rebased. |
Thank you so much! |
I try experimental implementation of catch the
KeyError
.