Class: NRSER::MethodMissingForwarder

Inherits:
BasicObject
Defined in:
lib/nrser/sugar/method_missing_forwarder.rb

Overview

A very simple class that forwards all method calls to the block it was initialized with (via #method_missing).

Instance Method Summary collapse

Constructor Details

#initialize(&forwarder) ⇒ MethodMissingForwarder

Instantiate a new ‘NRSER::MethodMissingForwarder` holding the forwarding block.

Parameters:

  • forwarder (Proc<(symbol:Symbol, *args, &block)>)

    Block that will receive all calls to #method_missing.



27
28
29
# File 'lib/nrser/sugar/method_missing_forwarder.rb', line 27

def initialize &forwarder
  @forwarder = forwarder
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Forwards all params to the ‘@forwarder` proc.

Parameters:

  • symbol (Symbol)

    The name of the method that was called.

  • args (Array)

    Any parameters the missing method was called with.

  • block (Proc?)

    The block the method was called with, if any.



46
47
48
# File 'lib/nrser/sugar/method_missing_forwarder.rb', line 46

def method_missing symbol, *args, &block
  @forwarder.call symbol, *args, &block
end