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
merged 2 commits into from
Jan 5, 2018

Conversation

nomadium
Copy link
Contributor

@nomadium nomadium commented Jan 5, 2018

Hi,

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. Ruby 2.5 Support #4876

Copy link
Member

@enebo enebo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 nomadium force-pushed the add-ruby-2.5-methods-to-key-error branch from 9346eff to 0cf8356 Compare January 5, 2018 16:43
@enebo enebo added this to the JRuby 9.3.0.0 milestone Jan 5, 2018
@enebo enebo merged commit 0cc6193 into jruby:ruby-2.5 Jan 5, 2018
@nomadium nomadium deleted the add-ruby-2.5-methods-to-key-error branch January 10, 2018 20:49
@enebo enebo modified the milestones: JRuby 9.3.0.0, JRuby 9.2.0.0 Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants