Class: RubyPatterns::VirtualProxy
- Inherits:
-
Object
- Object
- RubyPatterns::VirtualProxy
show all
- Defined in:
- lib/ruby_patterns/virtual_proxy.rb
Constant Summary
collapse
- GHOST =
"GHOST"
- LOADED =
"LOADED"
Instance Method Summary
collapse
Constructor Details
Returns a new instance of VirtualProxy.
13
14
15
16
|
# File 'lib/ruby_patterns/virtual_proxy.rb', line 13
def initialize(key)
@__key = key
@__real = nil
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/ruby_patterns/virtual_proxy.rb', line 36
def method_missing(name, *args, &block)
if __real.nil?
__load
end
__real.send(name, *args, &block)
end
|
Instance Method Details
#__load ⇒ Object
26
27
28
|
# File 'lib/ruby_patterns/virtual_proxy.rb', line 26
def __load
raise NotImplementedError, "Subclasses must implement `__load`."
end
|
#__state ⇒ Object
30
31
32
|
# File 'lib/ruby_patterns/virtual_proxy.rb', line 30
def __state
__real ? LOADED : GHOST
end
|
#inspect ⇒ Object
22
23
24
|
# File 'lib/ruby_patterns/virtual_proxy.rb', line 22
def inspect
"#<#{self.class.name} key=#{__key.inspect} #{__state}>"
end
|
#to_s ⇒ Object
18
19
20
|
# File 'lib/ruby_patterns/virtual_proxy.rb', line 18
def to_s
__key
end
|