File: C:/Ruby27-x64/share/ri/2.7.0/system/SimpleDelegator/cdesc-SimpleDelegator.ri
U:RDoc::NormalClass[iI"SimpleDelegator:ET@I"Delegator;To:RDoc::Markup::Document:@parts[o;;[o:RDoc::Markup::Paragraph;[ I"NA concrete implementation of Delegator, this class provides the means to ;TI"Sdelegate all supported method calls to the object passed into the constructor ;TI"Kand even to change the object being delegated to at a later time with ;TI"#__setobj__.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim;[I"class User
;TI" def born_on
;TI" Date.new(1989, 9, 10)
;TI" end
;TI" end
;TI"
;TI"+class UserDecorator < SimpleDelegator
;TI" def birth_year
;TI" born_on.year
;TI" end
;TI" end
;TI"
;TI"2decorated_user = UserDecorator.new(User.new)
;TI")decorated_user.birth_year #=> 1989
;TI"1decorated_user.__getobj__ #=> #<User: ...>
;T:@format0o; ;[I"TA SimpleDelegator instance can take advantage of the fact that SimpleDelegator ;TI"Sis a subclass of +Delegator+ to call <tt>super</tt> to have methods called on ;TI"#the object being delegated to.;T@o;;[I"(class SuperArray < SimpleDelegator
;TI" def [](*args)
;TI" super + 1
;TI" end
;TI" end
;TI"
;TI"#SuperArray.new([1])[0] #=> 2
;T;0o; ;[I"CHere's a simple example that takes advantage of the fact that ;TI"DSimpleDelegator's delegation object can be changed at any time.;T@o;;[I"class Stats
;TI" def initialize
;TI"+ @source = SimpleDelegator.new([])
;TI" end
;TI"
;TI" def stats(records)
;TI"% @source.__setobj__(records)
;TI"
;TI"* "Elements: #{@source.size}\n" +
;TI"2 " Non-Nil: #{@source.compact.size}\n" +
;TI"- " Unique: #{@source.uniq.size}\n"
;TI" end
;TI" end
;TI"
;TI"s = Stats.new
;TI",puts s.stats(%w{James Edward Gray II})
;TI"
puts
;TI".puts s.stats([1, 2, 3, nil, 4, 5, 1, 2])
;T;0o; ;[I"Prints:;T@o;;[I"Elements: 4
;TI" Non-Nil: 4
;TI" Unique: 4
;TI"
;TI"Elements: 8
;TI" Non-Nil: 7
;TI" Unique: 6;T;0:
@fileI"lib/delegate.rb;T:0@omit_headings_from_table_of_contents_below0;
0;0[ [ [ [[I"
class;T[[:public[ [:protected[ [:private[ [I"
instance;T[[;[[I"__getobj__;TI""../ruby-2.7.7/lib/delegate.rb;T[I"__setobj__;T@l[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;
0;0[I"lib/delegate.rb;T@WcRDoc::TopLevel