Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Wallet
- attr_reader :credit_balance # no longer attr_accessor!
- def withdraw(amount)
- raise InsufficientFundsError if amount > @credit_balance
- @credit_balance -= amount
- amount
- end
- end
- class Moviegoer
- # behavior delegation
- def pay(amount)
- wallet.withdraw(amount)
- end
- end
- class MovieTheater
- def collect_money(moviegoer, amount)
- @collected_amount += moviegoer.pay(amount)
- end
- end
Add Comment
Please, Sign In to add comment