2001-05-07 19:38:52 -04:00
|
|
|
|
-- forwatable.rb
|
|
|
|
|
$Release Version: 1.1 $
|
|
|
|
|
$Revision$
|
|
|
|
|
$Date$
|
|
|
|
|
|
2001-05-07 19:52:57 -04:00
|
|
|
|
=begin
|
2001-05-07 19:38:52 -04:00
|
|
|
|
= Forwardable
|
|
|
|
|
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD>饹<EFBFBD><EFBFBD><EFBFBD>Ф<EFBFBD><EFBFBD><EFBFBD>åɤΰѾ<EFBFBD><EFBFBD><EFBFBD>ǽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
== <20>Ȥ<EFBFBD><C8A4><EFBFBD>
|
|
|
|
|
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD>饹<EFBFBD><EFBFBD><EFBFBD>Ф<EFBFBD><EFBFBD><EFBFBD>extend<EFBFBD><EFBFBD><EFBFBD>ƻȤ<EFBFBD><EFBFBD>ޤ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
class Foo
|
|
|
|
|
extend Forwardable
|
|
|
|
|
|
|
|
|
|
def_delegators("@out", "printf", "print")
|
|
|
|
|
def_delegators(:@in, :gets)
|
|
|
|
|
def_delegator(:@contents, :[], "content_at")
|
|
|
|
|
end
|
|
|
|
|
f = Foo.new
|
|
|
|
|
f.printf ...
|
|
|
|
|
f.gets
|
|
|
|
|
f.content_at(1)
|
|
|
|
|
|
|
|
|
|
== <20><EFBFBD>å<EFBFBD>
|
|
|
|
|
|
|
|
|
|
--- Forwardable#def_instance_delegators(accessor, *methods)
|
|
|
|
|
|
|
|
|
|
((|methods|))<29><><EFBFBD>Ϥ<EFBFBD><CFA4>줿<EFBFBD><EFBFBD>åɤΥꥹ<CEA5>Ȥ<EFBFBD>((|accessor<6F><72>|))<29>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
<20>褦<EFBFBD>ˤ<EFBFBD><CBA4>ޤ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
--- Forwardable#def_instance_delegator(accessor, method, ali = method)
|
|
|
|
|
|
|
|
|
|
((||method|))<29><><EFBFBD>Ϥ<EFBFBD><CFA4>줿<EFBFBD><EFBFBD>åɤ<C3A5>((|accessor|))<29>˰Ѿ<CBB0><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>褦<EFBFBD>ˤ<EFBFBD>
|
|
|
|
|
<20>ޤ<EFBFBD>. ((|ali|))<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><C8A4><EFBFBD><EFBFBD>Ϥ<EFBFBD><CFA4>줿<EFBFBD>Ȥ<EFBFBD><C8A4><EFBFBD>, <20><EFBFBD>å<EFBFBD>((|ali|))<29><><EFBFBD>Ƥ<EFBFBD>
|
|
|
|
|
<20>줿<EFBFBD>Ȥ<EFBFBD><C8A4>ˤ<EFBFBD>, ((|accessor|))<29><><EFBFBD>Ф<EFBFBD>((|method|))<29><><EFBFBD>ƤӽФ<D3BD><D0A4>ޤ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
--- Forwardable#def_delegators(accessor, *methods)
|
|
|
|
|
|
|
|
|
|
((|Forwardable#def_instance_delegators|))<29><><EFBFBD><EFBFBD>̾<EFBFBD>Ǥ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
--- Forwardable#def_delegator(accessor, method, ali = method)
|
|
|
|
|
|
|
|
|
|
((|Forwardable#def_instance_delegator|))<29><><EFBFBD><EFBFBD>̾<EFBFBD>Ǥ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
= SingleForwardable
|
|
|
|
|
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD>֥<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><EFBFBD>Ф<EFBFBD>, <20><EFBFBD>åɤΰѾ<CEB0><D1BE><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ޤ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
== <20>Ȥ<EFBFBD><C8A4><EFBFBD>
|
|
|
|
|
|
|
|
|
|
<EFBFBD><EFBFBD><EFBFBD>֥<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><EFBFBD>Ф<EFBFBD><EFBFBD><EFBFBD>((|extend|))<29><><EFBFBD>ƻȤ<C6BB><C8A4>ޤ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
g = Goo.new
|
|
|
|
|
g.extend SingleForwardable
|
|
|
|
|
g.def_delegator("@out", :puts)
|
|
|
|
|
g.puts ...
|
|
|
|
|
|
|
|
|
|
== <20><EFBFBD>å<EFBFBD>
|
|
|
|
|
|
|
|
|
|
--- SingleForwardable#def_singleton_delegators(accessor, *methods)
|
|
|
|
|
|
|
|
|
|
((|methods|))<29><><EFBFBD>Ϥ<EFBFBD><CFA4>줿<EFBFBD><EFBFBD>åɤΥꥹ<CEA5>Ȥ<EFBFBD>((|accessor|))<29>˰Ѿ<CBB0><D1BE><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
<20>褦<EFBFBD>ˤ<EFBFBD><CBA4>ޤ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
--- SingleForwardable#def_singleton_delegator(accessor, method, ali = method)
|
|
|
|
|
|
|
|
|
|
((|method|))<29><><EFBFBD>Ϥ<EFBFBD><CFA4>줿<EFBFBD><EFBFBD>åɤ<C3A5>((|accessor|))<29>˰Ѿ<CBB0><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>褦<EFBFBD>ˤ<EFBFBD><CBA4><EFBFBD>
|
|
|
|
|
<20><>. ((|ali|))<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȥ<EFBFBD><C8A4><EFBFBD><EFBFBD>Ϥ<EFBFBD><CFA4>줿<EFBFBD>Ȥ<EFBFBD><C8A4><EFBFBD>, <20><EFBFBD>å<EFBFBD>((|ali|))<29><><EFBFBD>ƤФ<C6A4>
|
|
|
|
|
<20><><EFBFBD>Ȥ<EFBFBD><C8A4>ˤ<EFBFBD>, ((|accessor|))<29><><EFBFBD>Ф<EFBFBD>((|method|))<29><><EFBFBD>ƤӽФ<D3BD><D0A4>ޤ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
--- SingleForwardable#def_delegators(accessor, *methods)
|
|
|
|
|
|
|
|
|
|
((|SingleForwardable#def_singleton_delegators|))<29><><EFBFBD><EFBFBD>̾<EFBFBD>Ǥ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
--- SingleForwardable#def_delegator(accessor, method, ali = method)
|
|
|
|
|
|
|
|
|
|
((|SingleForwardable#def_singleton_delegator|))<29><><EFBFBD><EFBFBD>̾<EFBFBD>Ǥ<EFBFBD>.
|
2001-05-07 19:52:57 -04:00
|
|
|
|
=end
|