home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ruby164.zip / rbemx164.zip / ruby / share / doc / forwardable-1.1 / forwardable.rd next >
Text File  |  2001-06-18  |  2KB  |  84 lines

  1.  -- forwardable.rb
  2.                         
  3.                                                 $Release Version: 1.1 $
  4.                                                 $Revision: 1.1 $
  5.                                                 $Date: 2001/04/03 13:41:43 $
  6.                         Original version by Tosh
  7.  
  8. ==begin
  9.  
  10. = Forwardable
  11.  
  12. A Module to define delegations for selected methods to a class.
  13.  
  14. == Usage
  15.  
  16. Using through extending the class.
  17.   
  18.   class Foo
  19.     extend Forwardable
  20.  
  21.     def_delegators("@out", "printf", "print")
  22.     def_delegators(:@in, :gets)
  23.     def_delegator(:@contents, :[], "content_at")
  24.   end
  25.   f = Foo.new
  26.   f.printf ...
  27.   f.gets
  28.   f.content_at(1)
  29.  
  30. == Methods
  31.  
  32. --- Forwardable#def_instance_delegators(accessor, *methods)
  33.  
  34.       adding the delegations for each method of ((|methods|)) to
  35.       ((|accessor|)).
  36.  
  37. --- Forwardable#def_instance_delegator(accessor, method, ali = method)
  38.       
  39.       adding the delegation for ((|method|)) to ((|accessor|)). When
  40.       you give optional argument ((|ali|)), ((|ali|)) is used as the
  41.       name of the delegation method, instead of ((|method|)).
  42.  
  43. --- Forwardable#def_delegators(accessor, *methods)
  44.  
  45.       the alias of ((|Forwardable#def_instance_delegators|)).
  46.  
  47. --- Forwardable#def_delegator(accessor, method, ali = method)
  48.       
  49.       the alias of ((|Forwardable#def_instance_delegator|)).
  50.  
  51. = SingleForwardable
  52.  
  53. a Module to define delegations for selected methods to an object.
  54.  
  55. == Usage
  56.  
  57. Using through extending the object.
  58.  
  59.   g = Goo.new
  60.   g.extend SingleForwardable
  61.   g.def_delegator("@out", :puts)
  62.   g.puts ...
  63.  
  64. == Methods
  65.  
  66. --- SingleForwardable#def_singleton_delegators(accessor, *methods)
  67.  
  68.       adding the delegations for each method of ((|methods|)) to
  69.       ((|accessor|)).
  70.  
  71. --- SingleForwardable#def_singleton_delegator(accessor, method, ali = method)
  72.  
  73.       adding the delegation for ((|method|)) to ((|accessor|)). When
  74.       you give optional argument ((|ali|)), ((|ali|)) is used as the
  75.       name of the delegation method, instead of ((|method|)).
  76.  
  77. --- SingleForwardable#def_delegators(accessor, *methods)
  78.  
  79.       the alias of ((|SingleForwardable#def_instance_delegators|)).
  80.  
  81. --- SingleForwardable#def_delegator(accessor, method, ali = method)
  82.  
  83.       the alias of ((|SingleForwardable#def_instance_delegator|)).
  84. ==end