diff options
-rw-r--r-- | activesupport/lib/active_support/memoizable.rb | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb index 59fecbecb1..f7cd73d39c 100644 --- a/activesupport/lib/active_support/memoizable.rb +++ b/activesupport/lib/active_support/memoizable.rb @@ -1,19 +1,5 @@ module ActiveSupport module Memoizable #:nodoc: - def self.extended(obj) - klass = obj.respond_to?(:class_eval) ? obj : obj.metaclass - klass.class_eval do - def freeze - methods.each do |method| - if m = method.to_s.match(/^unmemoized_(.*)/) - send(m[1]) - end - end - super - end - end - end - def memoize(*symbols) symbols.each do |symbol| original_method = "unmemoized_#{symbol}" @@ -23,6 +9,18 @@ module ActiveSupport raise "Already memoized #{symbol}" if klass.instance_methods.map(&:to_s).include?(original_method) klass.class_eval <<-EOS, __FILE__, __LINE__ + unless instance_methods.map(&:to_s).include?("freeze_without_memoizable") + alias_method :freeze_without_memoizable, :freeze + def freeze + methods.each do |method| + if m = method.to_s.match(/^unmemoized_(.*)/) + send(m[1]) + end + end + freeze_without_memoizable + end + end + alias_method :#{original_method}, :#{symbol} def #{symbol}(reload = false) if !reload && defined? #{memoized_ivar} |