Skip to content

Instantly share code, notes, and snippets.

@AlexJWayne
Created April 20, 2015 20:00
Show Gist options
  • Save AlexJWayne/87c391cc46b410ca061d to your computer and use it in GitHub Desktop.
Save AlexJWayne/87c391cc46b410ca061d to your computer and use it in GitHub Desktop.
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