Class: VirtualProxy::Proxy

Inherits:
Delegator
  • Object
show all
Defined in:
lib/virtual_proxy/proxy.rb

Overview

Forward messages to a lazily-evaluated subject

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Proxy

Returns a new instance of Proxy.



4
5
6
# File 'lib/virtual_proxy/proxy.rb', line 4

def initialize(&block)
  @block = block
end

Instance Method Details

#__getobj__Object



8
9
10
# File 'lib/virtual_proxy/proxy.rb', line 8

def __getobj__
  @__getobj__ ||= @block.call
end

#__setobj__(&block) ⇒ Object



12
13
14
15
# File 'lib/virtual_proxy/proxy.rb', line 12

def __setobj__(&block)
  @block = block
  @__getobj__ = nil
end