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

Make payment.rb methods more concise #3734

Merged
merged 1 commit into from
Aug 19, 2020

Conversation

brchristian
Copy link
Contributor

@brchristian brchristian commented Aug 16, 2020

Description

In payment.rb, the source_required? method uses the foo.present? && foo.bar pattern, which can more concisely be expressed in Ruby >= 2.3 using the safe navigation operator as foo&.bar.

Likewise, the profiles_supported? method uses the foo.respond_to?(:bar) && foo.bar pattern, which can more concisely be expressed using Rails's try method as foo.try(:bar).

@brchristian
Copy link
Contributor Author

One additional thought is that we could also prepend with !! if we wanted to coerce the return value to a boolean.

@jarednorman
Copy link
Member

That might be worth it to be extra safe. You never know whether someone might be relying on == false or something. 😅

@brchristian
Copy link
Contributor Author

@jarednorman Done! 👍

Copy link
Member

@spaghetticode spaghetticode left a comment

Choose a reason for hiding this comment

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

@brchristian thanks! 👍

@spaghetticode spaghetticode merged commit 9f5873e into solidusio:master Aug 19, 2020
@brchristian brchristian deleted the patch-5 branch August 19, 2020 15:40
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.

3 participants