Module: Yoda::MissingDelegatable

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &blk) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/yoda/missing_delegatable.rb', line 17

def method_missing(method_name, *args, &blk)
  if delegate_missing_target&.respond_to?(method_name)
    delegate_missing_target.public_send(method_name, *args, &blk)
  else
    super
  end
end

Class Method Details

.included(klass) ⇒ Object



30
31
32
# File 'lib/yoda/missing_delegatable.rb', line 30

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#delegate_missing_targetObject?

Returns:

  • (Object, nil)


26
27
28
# File 'lib/yoda/missing_delegatable.rb', line 26

def delegate_missing_target
  self.class.delegate_missing_target && send(self.class.delegate_missing_target)
end

#respond_to_missing?(method_name, include_private) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/yoda/missing_delegatable.rb', line 13

def respond_to_missing?(method_name, include_private)
  delegate_missing_target&.respond_to?(method_name, include_private) || super
end