Class: Hoodie::Proxy

Inherits:
Module show all
Defined in:
lib/hoodie/proxy.rb

Overview

Turns object into a proxy which will forward all method missing calls.

Defined Under Namespace

Modules: Methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Proxy

Returns a new instance of Proxy.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hoodie/proxy.rb', line 26

def initialize(name, options = {})
  attr_reader name
  ivar = "@#{name}"

  attr_reader :__proxy_kind__, :__proxy_args__

  define_method(:initialize) do |proxy_target, *args, &block|
    instance_variable_set(ivar, proxy_target)

    @__proxy_kind__ = options.fetch(:kind) { proxy_target.class }
    @__proxy_args__ = args
  end

  define_method(:__proxy_target__) do
    instance_variable_get(ivar)
  end

  include Methods
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



24
25
26
# File 'lib/hoodie/proxy.rb', line 24

def name
  @name
end