ÿØÿà JFIF ÿÛ „ ( %!1!%*+...983,7(-.-
PK
]O!d d instance_delegate-i.rinu [ U:RDoc::AnyMethod[iI"instance_delegate:EFI""Forwardable#instance_delegate;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"GTakes a hash as its argument. The key is a symbol or an array of ;TI"Gsymbols. These symbols correspond to method names. The value is ;TI"9the accessor to which the methods will be delegated.;T:
@fileI"lib/forwardable.rb;T:0@omit_headings_from_table_of_contents_below0I"Kdelegate method => accessor
delegate [method, method, ...] => accessor;T0[[I"
delegate;Fo;; [ ;@;0I"(hash);T@FI"Forwardable;FcRDoc::NormalModule00PK
])o o
debug-c.rinu [ U:RDoc::Attr[iI"
debug:ETI"Forwardable::debug;TI"RW;T:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"MIf true, __FILE__ will remain in the backtrace in the event an ;TI"Exception is raised.;T:
@fileI"lib/forwardable.rb;T:0@omit_headings_from_table_of_contents_below0T@I"Forwardable;FcRDoc::NormalModule0PK
]b? ? def_delegator-i.rinu [ U:RDoc::AnyMethod[iI"def_delegator:EFI"Forwardable#def_delegator;TF:publico:RDoc::Markup::Document:@parts[ :
@fileI"lib/forwardable.rb;T:0@omit_headings_from_table_of_contents_below000[ I"%(accessor, method, ali = method);T@FI"Forwardable;FcRDoc::NormalModule0[@FI"def_instance_delegator;FPK
] cdesc-Forwardable.rinu [ U:RDoc::NormalModule[iI"Forwardable:EF@0o:RDoc::Markup::Document:@parts[o;;[ o:RDoc::Markup::Paragraph;[I"=The Forwardable module provides delegation of specified ;TI"Fmethods to a designated object, using the methods #def_delegator ;TI"and #def_delegators.;To:RDoc::Markup::BlankLine o; ;[ I">For example, say you have a class RecordCollection which ;TI"Ocontains an array @records. You could provide the lookup method ;TI"G#record_number(), which simply calls #[] on the @records ;TI"array, like this:;T@o:RDoc::Markup::Verbatim;[I"require 'forwardable'
;TI"
;TI"class RecordCollection
;TI" attr_accessor :records
;TI" extend Forwardable
;TI"4 def_delegator :@records, :[], :record_number
;TI" end
;T:@format0o; ;[I"*We can use the lookup method like so:;T@o;;[I"r = RecordCollection.new
;TI"r.records = [4,5,6]
;TI" r.record_number(0) # => 4
;T;0o; ;[I"GFurther, if you wish to provide the methods #size, #<<, and #map, ;TI"Ball of which delegate to @records, this is how you can do it:;T@o;;[I"=class RecordCollection # re-open RecordCollection class
;TI"2 def_delegators :@records, :size, :<<, :map
;TI" end
;TI"
;TI"r = RecordCollection.new
;TI"r.records = [1,2,3]
;TI"!r.record_number(0) # => 1
;TI"!r.size # => 3
;TI",r << 4 # => [1, 2, 3, 4]
;TI",r.map { |x| x * 2 } # => [2, 4, 6, 8]
;T;0o; ;[I":You can even extend regular objects with Forwardable.;T@o;;[ I"my_hash = Hash.new
;TI"Mmy_hash.extend Forwardable # prepare object for delegation
;TI"Pmy_hash.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts()
;TI"my_hash.puts "Howdy!"
;T;0S:RDoc::Markup::Heading:
leveli: textI"Another example;T@o; ;[ I"SWe want to rely on what has come before obviously, but with delegation we can ;TI"Qtake just the methods we need and even rename them as appropriate. In many ;TI"Lcases this is preferable to inheritance, which gives us the entire old ;TI"0interface, even if much of it isn't needed.;T@o;;[!I"class Queue
;TI" extend Forwardable
;TI"
;TI" def initialize
;TI"/ @q = [ ] # prepare delegate object
;TI" end
;TI"
;TI"7 # setup preferred interface, enq() and deq()...
;TI"& def_delegator :@q, :push, :enq
;TI"' def_delegator :@q, :shift, :deq
;TI"
;TI"A # support some general Array methods that fit Queues well
;TI"@ def_delegators :@q, :clear, :first, :push, :shift, :size
;TI" end
;TI"
;TI"q = Queue.new
;TI"q.enq 1, 2, 3, 4, 5
;TI"q.push 6
;TI"
;TI"q.shift # => 1
;TI"while q.size > 0
;TI" puts q.deq
;TI" end
;TI"
;TI"$q.enq "Ruby", "Perl", "Python"
;TI"puts q.first
;TI"
q.clear
;TI"puts q.first
;T;0o; ;[I"This should output:;T@o;;[I"2
;TI"3
;TI"4
;TI"5
;TI"6
;TI"
Ruby
;TI" nil
;T;0S;
;i;I"
Notes;T@o; ;[I"8Be advised, RDoc will not detect delegated methods.;T@o; ;[I"R+forwardable.rb+ provides single-method delegation via the def_delegator and ;TI"Ndef_delegators methods. For full-class delegation via DelegateClass, see ;TI"+delegate.rb+.;T:
@fileI"lib/forwardable.rb;T:0@omit_headings_from_table_of_contents_below0;0;0[[
I"
debug;TI"RW;T:publicTI"lib/forwardable.rb;T[U:RDoc::Constant[i I"FORWARDABLE_VERSION;FI"%Forwardable::FORWARDABLE_VERSION;T00o;;[o; ;[I" Version of +forwardable.rb+;T;@~;0@~@cRDoc::NormalModule0U;[i I"FILE_REGEXP;FI"Forwardable::FILE_REGEXP;T00o;;[ ;@~;0@~@@0[ [[I"
class;T[[;[ [:protected[ [:private[ [I"
instance;T[[;[[I"def_delegator;F@~[I"def_delegators;F@~[I"def_instance_delegator;F@~[I"def_instance_delegators;F@~[I"
delegate;F@~[I"instance_delegate;F@~[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[@~@~cRDoc::TopLevelPK
].Ô def_instance_delegator-i.rinu [ U:RDoc::AnyMethod[iI"def_instance_delegator:EFI"'Forwardable#def_instance_delegator;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"CDefine +method+ as delegator instance method with an optional ;TI"Balias name +ali+. Method calls to +ali+ will be delegated to ;TI"+accessor.method+.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"class MyQueue
;TI" extend Forwardable
;TI" attr_reader :queue
;TI" def initialize
;TI" @queue = []
;TI" end
;TI"
;TI"- def_delegator :@queue, :push, :mypush
;TI" end
;TI"
;TI"q = MyQueue.new
;TI"q.mypush 42
;TI"q.queue #=> [42]
;TI"!q.push 23 #=> NoMethodError;T:@format0:
@fileI"lib/forwardable.rb;T:0@omit_headings_from_table_of_contents_below000[[I"def_delegator;Fo;; [ ;@!;0I"%(accessor, method, ali = method);T@!FI"Forwardable;FcRDoc::NormalModule00PK
]L: def_instance_delegators-i.rinu [ U:RDoc::AnyMethod[iI"def_instance_delegators:EFI"(Forwardable#def_instance_delegators;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"CShortcut for defining multiple delegator methods, but with no ;TI"Cprovision for using a different name. The following two code ;TI""samples have the same effect:;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [
I"0def_delegators :@records, :size, :<<, :map
;TI"
;TI"$def_delegator :@records, :size
;TI""def_delegator :@records, :<<
;TI""def_delegator :@records, :map;T:@format0:
@fileI"lib/forwardable.rb;T:0@omit_headings_from_table_of_contents_below000[[I"def_delegators;Fo;; [ ;@;0I"(accessor, *methods);T@FI"Forwardable;FcRDoc::NormalModule00PK
]6
delegate-i.rinu [ U:RDoc::AnyMethod[iI"
delegate:EFI"Forwardable#delegate;TF:publico:RDoc::Markup::Document:@parts[ :
@fileI"lib/forwardable.rb;T:0@omit_headings_from_table_of_contents_below000[ I"(hash);T@FI"Forwardable;FcRDoc::NormalModule0[@FI"instance_delegate;FPK
]T6 6 def_delegators-i.rinu [ U:RDoc::AnyMethod[iI"def_delegators:EFI"Forwardable#def_delegators;TF:publico:RDoc::Markup::Document:@parts[ :
@fileI"lib/forwardable.rb;T:0@omit_headings_from_table_of_contents_below000[ I"(accessor, *methods);T@FI"Forwardable;FcRDoc::NormalModule0[@FI"def_instance_delegators;FPK
]O!d d instance_delegate-i.rinu [ PK
])o o
debug-c.rinu [ PK
]b? ? S def_delegator-i.rinu [ PK
] cdesc-Forwardable.rinu [ PK
].Ô def_instance_delegator-i.rinu [ PK
]L: def_instance_delegators-i.rinu [ PK
]6
delegate-i.rinu [ PK
]T6 6 " def_delegators-i.rinu [ PK