Class: Jsonite::LetsProxy
- Inherits:
- BasicObject
- Defined in:
- lib/jsonite/lets_proxy.rb
Instance Method Summary collapse
-
#initialize(object, context, lets = {}) ⇒ LetsProxy
constructor
A new instance of LetsProxy.
- #method_missing(name, *args, &block) ⇒ Object
Constructor Details
#initialize(object, context, lets = {}) ⇒ LetsProxy
Returns a new instance of LetsProxy.
6 7 8 9 10 11 12 |
# File 'lib/jsonite/lets_proxy.rb', line 6 def initialize object, context, lets = {} @__object__, @__context__, @__lets__ = object, context, lets @__memoized__ = ::Hash.new do |memoized, name| memoized[name] = instance_exec @__context__, &@__lets__.fetch(name) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/jsonite/lets_proxy.rb', line 14 def method_missing name, *args, &block if @__lets__.key?(name.to_s) @__memoized__[name.to_s] else @__object__.__send__ name, *args, &block end end |