Class: SyncEm
- Inherits:
-
Object
- Object
- SyncEm
- Defined in:
- lib/syncem.rb
Overview
SyncEm is a simple decorator of an existing object that makes all its methods thread-safe.
For more information read README file.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2018-2019 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
-
#initialize(origin) ⇒ SyncEm
constructor
A new instance of SyncEm.
- #method_missing(*args) ⇒ Object
- #respond_to?(method, include_private = false) ⇒ Boolean
- #respond_to_missing?(_method, _include_private = false) ⇒ Boolean
Constructor Details
#initialize(origin) ⇒ SyncEm
35 36 37 38 |
# File 'lib/syncem.rb', line 35 def initialize(origin) @origin = origin @mutex = Mutex.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/syncem.rb', line 40 def method_missing(*args) @mutex.synchronize do if @origin.respond_to?(args[0]) @origin.send(*args) else super end end end |
Instance Method Details
#respond_to?(method, include_private = false) ⇒ Boolean
50 51 52 |
# File 'lib/syncem.rb', line 50 def respond_to?(method, include_private = false) @origin.respond_to?(method, include_private) end |
#respond_to_missing?(_method, _include_private = false) ⇒ Boolean
54 55 56 |
# File 'lib/syncem.rb', line 54 def respond_to_missing?(_method, _include_private = false) true end |