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

Implement KeyError#receiver and KeyError#key #4940

merged 2 commits into from Jan 5, 2018


Copy link

@nomadium nomadium commented Jan 5, 2018


This is another feature targeting Ruby 2.5 [1]: KeyError#receiver and KeyError#key (feature #12063).

Note: the tests are copied from MRI.

To implement this I followed the approach used with NameError class, since it has a similar behaviour. If this is not the right approach, just let me know.

Thanks for your review and feedback.

  1. #4876
Copy link

@enebo enebo left a comment

Just make that one change and this looks great.

public RubyKeyError(Ruby runtime, RubyClass exceptionClass, String message, IRubyObject recv, IRubyObject key) {
super(runtime, exceptionClass, message);
this.receiver = recv == null ? runtime.getNil() : recv;

This comment has been minimized.


enebo Jan 5, 2018

Can you remove the null checks and above just pass in nil in the constructor above? I think we can accept the contract for this internal type can guarantee non-null values. In Array#fetch (and this is good to know) and all @JRubyMethods no passed in arguments will ever be null. We eliminate a lot of bulletproofing this way.

This comment has been minimized.


nomadium Jan 5, 2018
Author Contributor

Good observation, thanks. I believe I addressed your recommendation in the new commits I just pushed. Please let me know if there is something else to improve.

nomadium added 2 commits Jan 5, 2018
For more information, please see feature #12063.
@nomadium nomadium force-pushed the nomadium:add-ruby-2.5-methods-to-key-error branch from 9346eff to 0cf8356 Jan 5, 2018
@enebo enebo added this to the JRuby milestone Jan 5, 2018
@enebo enebo merged commit 0cc6193 into jruby:ruby-2.5 Jan 5, 2018
1 check was pending
1 check was pending
continuous-integration/travis-ci/pr The Travis CI build is in progress
@nomadium nomadium deleted the nomadium:add-ruby-2.5-methods-to-key-error branch Jan 10, 2018
@enebo enebo modified the milestones: JRuby, JRuby Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants