RubyMoney/money · error · TypeError

Can not divide by Money

Error message

Can not divide by Money

What it means

Error "Can not divide by Money" thrown in RubyMoney/money.

Source

Thrown at lib/money/money/arithmetic.rb:211

    # +Money/Numeric+ returns +Money+. +Money/Money+ returns +Float+.
    #
    # @param [Money, Numeric] value Number to divide by.
    #
    # @return [Money] The resulting money if you divide Money by a number.
    # @return [Float] The resulting number if you divide Money by a Money.
    #
    # @example
    #   Money.new(100) / 10            #=> #<Money @fractional=10>
    #   Money.new(100) / Money.new(10) #=> 10.0
    #
    def /(other)
      if other.is_a?(self.class)
        exchanged = other.exchange_to(currency)
        raise ZeroDivisionError, "divided by Money(0)" if exchanged.zero?

        fractional / as_d(exchanged.fractional).to_f
      else
        raise TypeError, "Can not divide by Money" if other.is_a?(CoercedNumeric)

        other = as_d(other)
        raise ZeroDivisionError, "divided by zero" if other.zero?

        dup_with(fractional: fractional / other)
      end
    end

    # Synonym for +#/+.
    #
    # @param [Money, Numeric] value Number to divide by.
    #
    # @return [Money] The resulting money if you divide Money by a number.
    # @return [Float] The resulting number if you divide Money by a Money.
    #
    # @see #/
    #
    def div(value)

View on GitHub (pinned to 26e2829c34)

When it happens

Trigger: Thrown at lib/money/money/arithmetic.rb:211 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/dad2e598cf9a3edf. Report an issue: GitHub.