Skip to content

Support an allocate method that is symmetrical with positive/negative amounts #190

Description

@rvanmelle

The current default :roundrobin allocator allows pennies to fall in different directions depending on whether the amounts are positive or negative. This is neither incorrect or correct, but could be surprising to money gem clients.

[12] pry(main)> Money.new(100, "USD").allocate([1 - fr, fr])
=> [#<Money value:11.51 currency:USD>, #<Money value:88.49 currency:USD>]
[13] pry(main)> Money.new(-100, "USD").allocate([1 - fr, fr])
=> [#<Money value:-11.50 currency:USD>, #<Money value:-88.50 currency:USD>]

A potential suggestion is introduce a new allocation strategy called :balanced or something :symmetrical that guarantees the same result will be produced with positive and negative amounts.

A bigger question is whether the current default of :roundrobin can be replaced with this new default... this could break the contract that they money gem has with existing customers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions