Class: Factrey::Proxy

Inherits:
BasicObject
Defined in:
lib/factrey/proxy.rb

Overview

An intermediate object to provide some notation combined with method_missing.

Examples:

class Foo
  def foo(name = nil)
    return Factrey::Proxy.new(self, __method__) unless name

    name
  end
end

Foo.new.foo.bar #=> :bar

Instance Method Summary collapse

Constructor Details

#initialize(receiver, method, *preargs) ⇒ Proxy

Returns a new instance of Proxy.

Parameters:

  • receiver (Object)
  • method (Symbol)
  • preargs (Array<Object>)


19
20
21
22
23
# File 'lib/factrey/proxy.rb', line 19

def initialize(receiver, method, *preargs)
  @receiver = receiver
  @method = method
  @preargs = preargs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object



28
29
30
# File 'lib/factrey/proxy.rb', line 28

def method_missing(method_name, ...)
  @receiver.__send__(@method, *@preargs, method_name, ...)
end