Class: Delegator

Inherits:
BasicObject
Defined in:
opal/stdlib/delegate.rb

Direct Known Subclasses

SimpleDelegator

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Delegator

Returns a new instance of Delegator.


2
3
4
# File 'opal/stdlib/delegate.rb', line 2

def initialize(obj)
  __setobj__(obj)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'opal/stdlib/delegate.rb', line 6

def method_missing(m, *args, &block)
  target = __getobj__

  if target.respond_to?(m)
    target.__send__(m, *args, &block)
  else
    super(m, *args, &block)
  end
end

Instance Method Details

#respond_to_missing?(m, include_private) ⇒ Boolean

Checks for a method provided by this the delegate object by forwarding the call through __getobj__.

Returns:


20
21
22
# File 'opal/stdlib/delegate.rb', line 20

def respond_to_missing?(m, include_private)
  __getobj__.respond_to?(m, include_private)
end