プロトタイプベース・オブジェクト指向
at TECH
424:デフォルトの名無しさん
04/02/08 16:35
>>423
乙。bank_account を組んでみました。
bank_account = Proto.new
bank_account.set "get_balance", proc{|this| this.get "balance"}
bank_account.set "set_balance", proc{|this, x| this.set "balance", x}
bank_account.call "set_balance", 200
bank_account.set "deposit", proc{|this, x| this.call "set_balance", (this.call "get_balance") + x}
bank_account.call "deposit", 50 => 250
bank_account.set "withdraw",
proc{|this, x| this.call "set_balance", [0, (this.call "get_balance") - x].max}
bank_account.call "withdraw", 100 => 150
bank_account.call "withdraw", 200 => 0
my_account = bank_account.inherit
my_account.call "set_balance", 100 => 100
my_account.call "deposit", 50 => 150
my_account.call "withdraw", 100 => 50
次ページ続きを表示1を表示最新レス表示スレッドの検索類似スレ一覧話題のニュースおまかせリスト▼オプションを表示暇つぶし2ch
5404日前に更新/368 KB
担当:undef