Created
March 11, 2012 00:16
-
-
Save takaheraw/2014185 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 AccountProxy | |
def initialize(real_account) | |
@subject = real_account | |
end | |
def method_missing(name, *args) | |
puts "Delegating #{name} message to subject." | |
@subject.send(name, *args) | |
end | |
end | |
class BankAccount | |
attr_reader :balance | |
def initialize(starting_balance=0) | |
@balance = starting_balance | |
end | |
def deposit(amount) | |
@balance += amount | |
end | |
def withdraw(amount) | |
@balance -= amount | |
end | |
end | |
ap = AccountProxy.new(BankAccount.new(100)) | |
ap.deposit(25) | |
ap.withdraw(50) | |
puts "account balance is now: #{ap.balance}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment