Class: CallbackAdapter
- Inherits:
-
Object
- Object
- CallbackAdapter
- Defined in:
- lib/callback-adapter.rb
Overview
Adapter from an callback-based interface to standard interface.
Instance Attribute Summary collapse
-
#object ⇒ Object
Holds the proxied object.
Instance Method Summary collapse
-
#initialize(object) ⇒ CallbackAdapter
constructor
Constructor.
-
#method_missing(name, *args) ⇒ Object
Methods call catcher.
Constructor Details
#initialize(object) ⇒ CallbackAdapter
Constructor.
23 24 25 |
# File 'lib/callback-adapter.rb', line 23 def initialize(object) @object = object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Methods call catcher. Thread safe.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/callback-adapter.rb', line 35 def method_missing(name, *args) returns = nil mutex = Mutex::new.lock @object.send(name, *args) do |*rets| case rets.length when 0 returns = nil when 1 returns = rets.first else returns = rets end mutex.unlock() end mutex.synchronize do return returns end end |
Instance Attribute Details
#object ⇒ Object
Holds the proxied object.
15 16 17 |
# File 'lib/callback-adapter.rb', line 15 def object @object end |