Skip to content

Commit ce03610

Browse files
committed
Ruby 2.x compat
1 parent 8d71d6a commit ce03610

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/money-rails/active_record/monetizable.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,19 @@ def track_monetized_attribute(name, value)
178178
end
179179
end
180180

181-
def read_monetized(name, subunit_name, options = {}, *args, **kwargs)
182-
# Get the cents
183-
amount = public_send(subunit_name, *args, **kwargs)
181+
def read_monetized(name, subunit_name, options = nil, *args, **kwargs)
182+
# Ruby 2.x compatibility
183+
if options.nil?
184+
options = kwargs
185+
kwargs = {}
186+
end
187+
188+
if kwargs.any?
189+
amount = public_send(subunit_name, *args, **kwargs)
190+
else
191+
# Ruby 2.x does not allow empty kwargs
192+
amount = public_send(subunit_name, *args)
193+
end
184194

185195
return if amount.nil? && options[:allow_nil]
186196
# Get the currency object

0 commit comments

Comments
 (0)