Class: Tsafe::Proxy
- Inherits:
-
Object
- Object
- Tsafe::Proxy
- Defined in:
- lib/tsafe_proxy.rb
Overview
Instance Method Summary collapse
-
#initialize(args) ⇒ Proxy
constructor
Spawns needed vars.
-
#method_missing(method_name, *args, &block) ⇒ Object
Proxies all calls to this object through the mutex.
Constructor Details
#initialize(args) ⇒ Proxy
Spawns needed vars.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tsafe_proxy.rb', line 11 def initialize(args) if args[:monitor] @mutex = Monitor.new elsif args[:mutex] @mutex = args[:mutex] else @mutex = Mutex.new end @obj = args[:obj] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Proxies all calls to this object through the mutex.
24 25 26 27 28 |
# File 'lib/tsafe_proxy.rb', line 24 def method_missing(method_name, *args, &block) @mutex.synchronize do @obj.__send__(method_name, *args, &block) end end |