diff options
Diffstat (limited to 'lib/singleton.rb')
-rw-r--r-- | lib/singleton.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/lib/singleton.rb b/lib/singleton.rb index 368febc74d..b433208e01 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -120,6 +120,15 @@ module Singleton instance end + def instance # :nodoc: + return @singleton__instance__ if @singleton__instance__ + @singleton__mutex__.synchronize { + return @singleton__instance__ if @singleton__instance__ + @singleton__instance__ = new() + } + @singleton__instance__ + end + private def inherited(sub_klass) @@ -134,14 +143,6 @@ module Singleton @singleton__instance__ = nil @singleton__mutex__ = Thread::Mutex.new } - def klass.instance # :nodoc: - return @singleton__instance__ if @singleton__instance__ - @singleton__mutex__.synchronize { - return @singleton__instance__ if @singleton__instance__ - @singleton__instance__ = new() - } - @singleton__instance__ - end klass end |