Module: SingleForwardable
- Defined in:
- opal/stdlib/forwardable.rb
Instance Method Summary collapse
- #def_single_delegator(accessor, method, ali = method) ⇒ Object (also: #def_delegator)
- #def_single_delegators(accessor, *methods) ⇒ Object (also: #def_delegators)
- #single_delegate(hash) ⇒ Object (also: #delegate)
Instance Method Details
#def_single_delegator(accessor, method, ali = method) ⇒ Object Also known as: def_delegator
56 57 58 59 60 61 62 63 64 65 66 |
# File 'opal/stdlib/forwardable.rb', line 56 def def_single_delegator(accessor, method, ali = method) if accessor.to_s.start_with? ?@ define_singleton_method ali do |*args, &block| instance_variable_get(accessor).__send__(method, *args, &block) end else define_singleton_method ali do |*args, &block| __send__(accessor).__send__(method, *args, &block) end end end |
#def_single_delegators(accessor, *methods) ⇒ Object Also known as: def_delegators
48 49 50 51 52 53 54 |
# File 'opal/stdlib/forwardable.rb', line 48 def def_single_delegators(accessor, *methods) methods.each {|method| next if %w[__send__ __id__].include? method def_single_delegator(accessor, method) } end |
#single_delegate(hash) ⇒ Object Also known as: delegate
38 39 40 41 42 43 44 45 46 |
# File 'opal/stdlib/forwardable.rb', line 38 def single_delegate(hash) hash.each {|methods, accessor| methods = [methods] unless methods.respond_to? :each methods.each {|method| def_single_delegator(accessor, method) } } end |