-
Notifications
You must be signed in to change notification settings - Fork 114
Use instance variable for currency to reduce parameter passing #198
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
Use instance variable for currency to reduce parameter passing #198
Conversation
yukideluxe
left a comment
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.
looks good to me! Thanks, @RubenIgnacio!
what do you think, @sunny?
sunny
left a comment
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 like these small changes that add readibility and are easy to review \o/
lib/monetize/parser.rb
Outdated
| @input = input.to_s.strip | ||
| @fallback_currency = fallback_currency | ||
| @options = options | ||
| @currency = Money::Currency.wrap(parse_currency) |
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.
What do you think about making that into a private method with memoisation instead of an attr_reader? E.g.:
def currency
@currency ||= Money::Currency.wrap(parse_currency)
endIt doesn’t make a big difference but in the rare case where we don’t use that method, the parsing won’t be called.
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 really have no preference, I also like that approach and we just leave initialize for instantiating the arguments 🙆🏻♀️
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.
That makes total sense for me, I’ll update the code.
I have a question, I actually have a few similar changes that are chained to this branch. Should I open them as separate PRs even if they depend on this one?
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.
What would be lovely would be chaining them by making PRs where the base is the previous PR, this way the diff is only focused on one change.
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.
thanks!
sunny
left a comment
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.
👏🏻
Refactor the
Monetize::Parserclass to store the parsed currency in an instance variable during initialization. This simplifies the method calls by removing the need to pass the currency as an explicit argument.