Created
June 21, 2011 02:02
-
-
Save nahi/1037082 to your computer and use it in GitHub Desktop.
Patch for ruby_1_8_7 singleton.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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