Created
April 20, 2015 20:00
-
-
Save AlexJWayne/87c391cc46b410ca061d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Money | |
def evenly_divided(parts) | |
extra = cents % parts | |
(0...parts).map do |i| | |
add1 = i < extra ? 1 : 0 | |
Money.from_cents cents / parts + add1 | |
end | |
end | |
end | |
Money.new(0.10).evenly_divided(3) | |
#=> [0.04, 0.03, 0.03] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment