Class: RubyChangeMaker::Change
- Inherits:
-
Object
- Object
- RubyChangeMaker::Change
- Defined in:
- lib/rubychangemaker/rubychangemaker.rb
Constant Summary collapse
- BILLS =
google: common usd denominations
[ 100, 50, 20, 10, 5, 2, 1 ]
- COINS =
[ 50, 25, 10, 5, 1 ]
Instance Method Summary collapse
-
#initialize ⇒ Change
constructor
A new instance of Change.
-
#make_change(amount) ⇒ Object
split the denomination entered into bills and coins then, determine change using least amount of bills and coins.
Constructor Details
#initialize ⇒ Change
Returns a new instance of Change.
14 15 |
# File 'lib/rubychangemaker/rubychangemaker.rb', line 14 def initialize() end |
Instance Method Details
#make_change(amount) ⇒ Object
split the denomination entered into bills and coins then, determine change using least amount of bills and coins
19 20 21 22 23 24 25 |
# File 'lib/rubychangemaker/rubychangemaker.rb', line 19 def make_change( amount ) #REMOVED IN REFACTOR: coins = changer( pull_cents( f ), COINS ) #REMOVED IN REFACTOR: bills = changer( pull_bills( f ), BILLS ) coins = changer( pull_currency( amount ){ | s, idx | currency = s[ idx + 1..-1 ] }, COINS ) bills = changer( pull_currency( amount ){ | s, idx | currency = s[ 0...idx ] }, BILLS ) [ bills, coins ] end |