diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-07-18 23:30:36 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-18 23:30:36 -0500 |
commit | c609be45966316bb107e0bad2b0935ac4a0d0c41 (patch) | |
tree | d1663e5137a68000678a15e4369281a79cd4b2ae /activesupport/lib | |
parent | d39485078ec56e25a96e97d44b53498d8a1c7426 (diff) | |
download | rails-c609be45966316bb107e0bad2b0935ac4a0d0c41.tar.gz rails-c609be45966316bb107e0bad2b0935ac4a0d0c41.tar.bz2 rails-c609be45966316bb107e0bad2b0935ac4a0d0c41.zip |
Ruby 1.9: Ensure Memoizable#freeze is only overriden once to avoid an endless loop
Diffstat (limited to 'activesupport/lib')
-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} |