lib/memoizable.rb in memoizable-0.1.0 vs lib/memoizable.rb in memoizable-0.2.0
- old
+ new
@@ -1,17 +1,30 @@
+require 'thread_safe'
+
+require 'memoizable/instance_methods'
+require 'memoizable/method_builder'
+require 'memoizable/module_methods'
+require 'memoizable/memory'
+require 'memoizable/version'
+
+# Allow methods to be memoized
module Memoizable
- CACHE = Hash.new
- module ClassMethods
- def memoize(name)
- original = "__original__#{name}"
- alias_method original, name
- define_method(name) do |*args|
- CACHE[self.to_s.unpack("a*")<<name.to_s.unpack("a*")<<args] ||=
- send(original, *args)
- end
+
+ # Default freezer
+ Freezer = lambda { |object| object.freeze }.freeze
+
+ # Hook called when module is included
+ #
+ # @param [Module] descendant
+ # the module or class including Memoizable
+ #
+ # @return [self]
+ #
+ # @api private
+ def self.included(descendant)
+ descendant.module_eval do
+ extend ModuleMethods
+ include InstanceMethods
end
end
-
- def self.included(receiver)
- receiver.extend ClassMethods
- end
-end
\ No newline at end of file
+
+end # Memoizable