Method: Money#split
- Defined in:
- lib/money/money.rb
#split ⇒ Array<Money>
Splits a given amount in parts without losing pennies. The left-over pennies will be distributed round-robin amongst the parties. This means that parts listed first will likely receive more pennies than ones listed later.
Pass [2, 1, 1] as input to give twice as much to part1 as part2 or part3 which results in 50% of the cash to party1, 25% to part2, and 25% to part3. Passing a number instead of an array will split the amount evenly (without losing pennies when rounding).
587 588 589 590 |
# File 'lib/money/money.rb', line 587 def allocate(parts) amounts = Money::Allocation.generate(fractional, parts, !Money.default_infinite_precision) amounts.map { |amount| dup_with(fractional: amount) } end |