RubyMoney/money · error · TypeError

Can't multiply a #{self.class.name} by a #{other.class.name}

Error message

Can't multiply a #{self.class.name} by a #{other.class.name}'s value

What it means

Error "Can't multiply a #{self.class.name} by a #{other.class.name}'s value" thrown in RubyMoney/money.

Source

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

    # +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.
    #
    # @return [Money] The resulting money.
    #
    # @raise [TypeError] If +value+ is NOT a number.
    #
    # @example
    #   Money.new(100) * 2 #=> #<Money @fractional=200>
    #
    def *(other)
      other = other.value if other.is_a?(CoercedNumeric)
      if other.is_a? Numeric
        dup_with(fractional: fractional * other)
      else
        raise TypeError, "Can't multiply a #{self.class.name} by a #{other.class.name}'s value"
      end
    end

    # Divides the monetary value with the given number and returns a new +Money+
    # object with this monetary value and the same currency.
    # Can also divide by another +Money+ object to get a ratio.
    #
    # +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
    #

View on GitHub (pinned to 26e2829c34)

When it happens

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