Use instance variable for currency to reduce parameter passing#198
Use instance variable for currency to reduce parameter passing#198sunny merged 2 commits intoRubyMoney:mainfrom
Conversation
yukideluxe
left a comment
There was a problem hiding this comment.
looks good to me! Thanks, @RubenIgnacio!
what do you think, @sunny?
sunny
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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.
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.