Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Patch for ruby_1_8_7 singleton.rb

View gist:1037082
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Index: lib/singleton.rb
===================================================================
--- lib/singleton.rb (revision 32126)
+++ lib/singleton.rb (working copy)
@@ -94,9 +94,12 @@
@__instance__ = new
ensure
if @__instance__
- class <<self
- remove_method :instance
- def instance; @__instance__ end
+ # Check method existence to reduce redefinition warning.
+ unless self.respond_to?(:instance)
+ # It's doing test-then-set without a lock so there's a race to
+ # override existing method that causes the redefinition warning.
+ # We allow it since method redefinition is thread-safe for calling.
+ def self.instance; @__instance__ end
end
else
@__instance__ = nil # failed instance creation
@@ -111,9 +114,9 @@
@__instance__ = new
ensure
if @__instance__
- class <<self
- remove_method :instance
- def instance; @__instance__ end
+ # See the comment for self.instance above.
+ unless self.respond_to?(:instance)
+ def self.instance; @__instance__ end
end
else
@__instance__ = nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.