* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / doc / forwardable.rd
blob0eca25b90a99884d11e8d6bbc727aa0ee462d2f9
1  -- forwardable.rb
2                                                 
3                                                 $Release Version: 1.1 $
4                                                 $Revision$
5                                                 Original version by Tosh
7 =begin
9 = Forwardable
11 A Module to define delegations for selected methods to a class.
13 == Usage
15 Using through extending the class.
16   
17   class Foo
18     extend Forwardable
20     def_delegators("@out", "printf", "print")
21     def_delegators(:@in, :gets)
22     def_delegator(:@contents, :[], "content_at")
23   end
24   f = Foo.new
25   f.printf ...
26   f.gets
27   f.content_at(1)
29 == Methods
31 --- Forwardable#def_instance_delegators(accessor, *methods)
33       adding the delegations for each method of ((|methods|)) to
34       ((|accessor|)).
36 --- Forwardable#def_instance_delegator(accessor, method, ali = method)
37       
38       adding the delegation for ((|method|)) to ((|accessor|)). When
39       you give optional argument ((|ali|)), ((|ali|)) is used as the
40       name of the delegation method, instead of ((|method|)).
42 --- Forwardable#def_delegators(accessor, *methods)
44       the alias of ((|Forwardable#def_instance_delegators|)).
46 --- Forwardable#def_delegator(accessor, method, ali = method)
47       
48       the alias of ((|Forwardable#def_instance_delegator|)).
50 = SingleForwardable
52 a Module to define delegations for selected methods to an object.
54 == Usage
56 Using through extending the object.
58   g = Goo.new
59   g.extend SingleForwardable
60   g.def_delegator("@out", :puts)
61   g.puts ...
63 == Methods
65 --- SingleForwardable#def_singleton_delegators(accessor, *methods)
67       adding the delegations for each method of ((|methods|)) to
68       ((|accessor|)).
70 --- SingleForwardable#def_singleton_delegator(accessor, method, ali = method)
72       adding the delegation for ((|method|)) to ((|accessor|)). When
73       you give optional argument ((|ali|)), ((|ali|)) is used as the
74       name of the delegation method, instead of ((|method|)).
76 --- SingleForwardable#def_delegators(accessor, *methods)
78       the alias of ((|SingleForwardable#def_instance_delegators|)).
80 --- SingleForwardable#def_delegator(accessor, method, ali = method)
82       the alias of ((|SingleForwardable#def_instance_delegator|)).
83 =end