- 1 名前:デフォルトの名無しさん [03/12/08 21:30]
- オブジェクトを複製または継承によって生成を行う言語,
プロトタイプベース・オブジェクト指向言語について語りましょうよ. 関連リンク >>2
- 411 名前:デフォルトの名無しさん mailto:sage [04/02/07 22:25]
- 委譲するオブジェクトのリストでも持っといて、自分のスロットに
見つからなかったらそっちから順番に検索…とかじゃ駄目っすかね?
- 412 名前:n [04/02/08 00:08]
- class Proto
attr_accessor :slot,:proto,:mixin def initialize; @slot = Hash.new; @proto = nil; @mixin = Array.new; end def inherit; obj = Proto.new; obj.proto = self; return obj; end def call(key); if @slot.key?(key) then @slot[key].call else self.proto.call(key) end;end def set(key,val); @slot[key]=val; end def get(key)@slot[key]end end foo = Proto.new foo.set "foo",proc{puts"foo"} foo.set "hello",proc{puts"Hello,Foo!"} bar = foo.inherit bar.set "bar",proc{puts"foo"} bar.call("foo") bar.call("hello") hoge = bar.inherit hoge.set "hello",proc{puts"Hello,Hoge!"} fuga = hoge.inherit fuga.call("foo") fuga.call("hello") foo.call("hello") こんな感じですか?
|

|