RubyMoney/money · error · TypeError
Can't add or subtract a non-zero #{value.class.name} value
Error message
Can't add or subtract a non-zero #{value.class.name} value What it means
Error "Can't add or subtract a non-zero #{value.class.name} value" thrown in RubyMoney/money.
Source
Thrown at lib/money/money/arithmetic.rb:153
#
# @param [Money] other Other +Money+ object to subtract.
# @return [Money]
#
# @example
# Money.new(100) - Money.new(99) #=> #<Money @fractional=1>
[:+, :-].each do |op|
non_zero_message = lambda do |value|
"Can't add or subtract a non-zero #{value.class.name} value"
end
define_method(op) do |other|
case other
when Money
other = other.exchange_to(currency)
new_fractional = fractional.public_send(op, other.fractional)
dup_with(fractional: new_fractional)
when CoercedNumeric
raise TypeError, non_zero_message.call(other.value) unless other.zero?
dup_with(fractional: other.value.public_send(op, fractional))
when Numeric
raise TypeError, non_zero_message.call(other) unless other.zero?
self
else
raise TypeError, "Unsupported argument type: #{other.class.name}"
end
end
end
# Multiplies the monetary value with the given number and returns a new
# +Money+ object with this monetary value and the same currency.
#
# Note that you can't multiply a Money object by an other +Money+ object.
#
# @param [Numeric] value Number to multiply by.View on GitHub (pinned to 26e2829c34)
When it happens
Trigger: Thrown at lib/money/money/arithmetic.rb:153 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of RubyMoney/money@26e2829c34 (2026-08-23).
Data as JSON: /api/errors/835c7d51053a27ce.
Report an issue: GitHub.