RubyMoney/money · error · ArgumentError

need at least one part

Error message

need at least one part

What it means

Error "need at least one part" thrown in RubyMoney/money.

Source

Thrown at lib/money/money/allocation.rb:34

    # @param decimal_cutoff [Boolean, Integer] Controls per-split precision:
    #   - When true, splits are truncated to whole amounts.
    #   - When an Integer N, splits are rounded to N decimal places.
    #   - When false or nil, no rounding/truncation is applied.
    #   Defaults to true (whole amounts).
    #
    # @return [Array<Numeric>] An array containing the allocated amounts.
    # @raise [ArgumentError] If parts is empty or not provided.
    def self.generate(amount, parts, decimal_cutoff = true)
      parts =
        if parts.is_a?(Numeric)
          Array.new(parts, 1)
        elsif parts.all?(&:zero?)
          Array.new(parts.count, 1)
        else
          parts.dup
        end

      raise ArgumentError, "need at least one part" if parts.empty?

      if [amount, *parts].any? { |i| i.is_a?(BigDecimal) || i.is_a?(Float) || i.is_a?(Rational) }
        amount = convert_to_big_decimal(amount)
        parts.map! { |p| convert_to_big_decimal(p) }
      end

      result = []
      remaining_amount = amount
      round_to_whole = decimal_cutoff.is_a?(TrueClass)
      round_to_precision = decimal_cutoff.is_a?(Integer)

      parts_sum = parts.sum

      until parts.empty?
        part = parts.pop

        current_split = 0
        if parts_sum > 0

View on GitHub (pinned to 26e2829c34)

When it happens

Trigger: Thrown at lib/money/money/allocation.rb:34 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/ab3ffbe5a8795efb. Report an issue: GitHub.