Skip to content

Instantly share code, notes, and snippets.

@takaheraw
Created March 11, 2012 00:16
Show Gist options
  • Save takaheraw/2014185 to your computer and use it in GitHub Desktop.
Save takaheraw/2014185 to your computer and use it in GitHub Desktop.
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