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

Test for the new exception of delegate_missing_to #30191

Merged
merged 6 commits into from Aug 12, 2017

Conversation

colorfulfool
Copy link
Contributor

A follow-up to the change to delegate_missing_to made in #30084.

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

Copy link
Member

@rafaelfranca rafaelfranca left a comment

Choose a reason for hiding this comment

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

Based on @matthewd's comment in the original PR, can you change the implementation to only check for nil if super raises NoMethodError?

@colorfulfool
Copy link
Contributor Author

colorfulfool commented Aug 11, 2017

Done. I didn't go this way initially because the code turns out not pretty. Is there a better way to write it?

end

def delegation_error_if_target_nil(target, method)
begin
Copy link
Member

Choose a reason for hiding this comment

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

You can remove the begin here.

end
end

def delegation_error_if_target_nil(target, method)
Copy link
Member

Choose a reason for hiding this comment

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

This method should be private, and starts with _ to avoid conflicts with the methods in the including class.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we extract the method at all, we're still monkey patching a core object here. Any pollution counts.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't think it is necessary. begin/end inside that else is good enough.

@rafaelfranca
Copy link
Member

I think that is fine

@colorfulfool
Copy link
Contributor Author

colorfulfool commented Aug 11, 2017

Is delegate_missing_to meant to be used multiple times on the same class? If not, I can eliminate most of _delegation_error_if_target_nil arguments.

I'd say it isn't, because you can instead do

delegate_missing_to :person_responsible

def person_responsible
  president || chief || captain
end

@rafaelfranca
Copy link
Member

It is not, because only the last call is going to be used.

@rafaelfranca
Copy link
Member

I think we can go with the version without the private method just to avoid polluting the caller more

@rafaelfranca rafaelfranca merged commit e6c310b into rails:master Aug 12, 2017
@rafaelfranca
Copy link
Member

rafaelfranca commented Aug 12, 2017

This is amazing. Thank you for doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants