Skip to content

Commit e22216b

Browse files
committed
Refactor currency initialization to use a method for lazy loading
1 parent 7f5db48 commit e22216b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

lib/monetize/parser.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def initialize(input, fallback_currency = Money.default_currency, options = {})
4040
@input = input.to_s.strip
4141
@fallback_currency = fallback_currency
4242
@options = options
43-
@currency = Money::Currency.wrap(parse_currency)
4443
end
4544

4645
def parse
@@ -69,7 +68,11 @@ def to_big_decimal(value)
6968
fail ParseError, err.message
7069
end
7170

72-
attr_reader :input, :fallback_currency, :options, :currency
71+
attr_reader :input, :fallback_currency, :options
72+
73+
def currency
74+
@currency ||= Money::Currency.wrap(parse_currency)
75+
end
7376

7477
def parse_currency
7578
computed_currency = nil

0 commit comments

Comments
 (0)