Money::Allocate
Instance methods
Allocates money between different parties without losing pennies. After the mathematical split has been performed, leftover pennies will be distributed round-robin amongst the parties. This means that parties listed first will likely receive more pennies than ones that are listed later.
# Give 50% of the cash to party 1, 25% to party 2, and 25% to party 3.
Money.new(10_00, "USD").allocate([0.5, 0.25, 0.25]).map(&.cents)
# => [5_00, 2_50, 2_50]
Money.new(5, "USD").allocate({0.3, 0.7}).map(&.cents)
# => [2, 3]
Money.new(100, "USD").allocate(0.33, 0.33, 0.33).map(&.cents)
# => [34, 33, 33]
Allocates money between different parties without losing pennies. After the mathematical split has been performed, leftover pennies will be distributed round-robin amongst the parties. This means that parties listed first will likely receive more pennies than ones that are listed later.
# Give 50% of the cash to party 1, 25% to party 2, and 25% to party 3.
Money.new(10_00, "USD").allocate([0.5, 0.25, 0.25]).map(&.cents)
# => [5_00, 2_50, 2_50]
Money.new(5, "USD").allocate({0.3, 0.7}).map(&.cents)
# => [2, 3]
Money.new(100, "USD").allocate(0.33, 0.33, 0.33).map(&.cents)
# => [34, 33, 33]