Module: Singleton
- Defined in:
- lib/framework/singleton.rb
Overview
require ‘thread’
Defined Under Namespace
Modules: SingletonClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#_dump(depth = -1)) ⇒ Object
default marshalling strategy.
-
#clone ⇒ Object
disable build-in copying methods.
- #dup ⇒ Object
Class Method Details
.__init__(klass) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/framework/singleton.rb', line 100 def __init__(klass) klass.instance_eval { @singleton__instance__ = nil @singleton__mutex__ = Mutex.new } def klass.instance return @singleton__instance__ if @singleton__instance__ @singleton__mutex__.synchronize { return @singleton__instance__ if @singleton__instance__ @singleton__instance__ = new() } @singleton__instance__ end klass end |
Instance Method Details
#_dump(depth = -1)) ⇒ Object
default marshalling strategy
75 76 77 |
# File 'lib/framework/singleton.rb', line 75 def _dump(depth = -1) '' end |
#clone ⇒ Object
disable build-in copying methods
67 68 69 |
# File 'lib/framework/singleton.rb', line 67 def clone raise TypeError, "can't clone instance of singleton #{self.class}" end |
#dup ⇒ Object
70 71 72 |
# File 'lib/framework/singleton.rb', line 70 def dup raise TypeError, "can't dup instance of singleton #{self.class}" end |