2001-05-07 19:38:52 -04:00
|
|
|
-- forwatable.rb
|
|
|
|
$Release Version: 1.1 $
|
|
|
|
$Revision$
|
|
|
|
|
2001-05-07 19:52:57 -04:00
|
|
|
=begin
|
2001-05-07 19:38:52 -04:00
|
|
|
= Forwardable
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
クラスに対しメソッドの委譲機能を定義します.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
== 使い方
|
2001-05-07 19:38:52 -04:00
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
クラスに対してextendして使います.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
== メソッド
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
--- Forwardable#def_instance_delegators(accessor, *methods)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
((|methods|))で渡されたメソッドのリストを((|accessorに|))委譲する
|
|
|
|
ようにします.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
--- Forwardable#def_instance_delegator(accessor, method, ali = method)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
((||method|))で渡されたメソッドを((|accessor|))に委譲するようにし
|
|
|
|
ます. ((|ali|))が引数として渡されたときは, メソッド((|ali|))が呼ば
|
|
|
|
れたときには, ((|accessor|))に対し((|method|))を呼び出します.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
--- Forwardable#def_delegators(accessor, *methods)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
((|Forwardable#def_instance_delegators|))の別名です.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
--- Forwardable#def_delegator(accessor, method, ali = method)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
((|Forwardable#def_instance_delegator|))の別名です.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
= SingleForwardable
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
オブジェクトに対し, メソッドの委譲機能を定義します.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
== 使い方
|
2001-05-07 19:38:52 -04:00
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
オブジェクトに対して((|extend|))して使います.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
g = Goo.new
|
|
|
|
g.extend SingleForwardable
|
|
|
|
g.def_delegator("@out", :puts)
|
|
|
|
g.puts ...
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
== メソッド
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
--- SingleForwardable#def_singleton_delegators(accessor, *methods)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
((|methods|))で渡されたメソッドのリストを((|accessor|))に委譲する
|
|
|
|
ようにします.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
--- SingleForwardable#def_singleton_delegator(accessor, method, ali = method)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
((|method|))で渡されたメソッドを((|accessor|))に委譲するようにしま
|
|
|
|
す. ((|ali|))が引数として渡されたときは, メソッド((|ali|))が呼ばれ
|
|
|
|
たときには, ((|accessor|))に対し((|method|))を呼び出します.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
--- SingleForwardable#def_delegators(accessor, *methods)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
((|SingleForwardable#def_singleton_delegators|))の別名です.
|
2001-05-07 19:38:52 -04:00
|
|
|
|
|
|
|
--- SingleForwardable#def_delegator(accessor, method, ali = method)
|
|
|
|
|
2011-09-04 08:22:46 -04:00
|
|
|
((|SingleForwardable#def_singleton_delegator|))の別名です.
|
2001-05-07 19:52:57 -04:00
|
|
|
=end
|