Skip to content
Browse files

Use Kernel mixin for instance.rb to prevent conflict with rails. (#55)

  • Loading branch information...
1 parent 09c3963 commit 346a6b5d79dcafe093e610f9003d38fc8cad7511 @trans trans committed May 27, 2012
Showing with 22 additions and 13 deletions.
  1. +22 −13 lib/core/facets/instance.rb
View
35 lib/core/facets/instance.rb
@@ -1,16 +1,3 @@
-module Kernel
- INSTANCES = {}
-
- # Returns an instance of Instance for +self+,
- # which allows convenient access to an object's
- # internals.
-
- def instance
- INSTANCES[self] ||= Instance.new(self)
- end
-
-end
-
# = Instance Class
#
# class Friend
@@ -30,6 +17,24 @@ class Instance
include Enumerable
+ module Kernel
+ # Returns an instance of Instance for +self+,
+ # which allows convenient access to an object's
+ # internals.
+ def instance
+ Instance.instance(self)
+ end
+ end
+
+ # Instance table acts as a global cache for instances of Instance.
+ @table = {}
+
+ # Instance is multiton. Use this method instead of #new to get a the
+ # cached instance.
+ def self.instance(delegate)
+ @table[delegate] ||= Instance.new(delegate)
+ end
+
#
def initialize(delegate)
@delegate = delegate
@@ -155,3 +160,7 @@ def atize(name)
end
+module Kernel
+ include Instance::Kernel
+end
+

0 comments on commit 346a6b5

Please sign in to comment.
Something went wrong with that request. Please try again.