diff options
Diffstat (limited to 'activesupport/lib/active_support/memoizable.rb')
-rw-r--r-- | activesupport/lib/active_support/memoizable.rb | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb index 5af50df023..d06250171a 100644 --- a/activesupport/lib/active_support/memoizable.rb +++ b/activesupport/lib/active_support/memoizable.rb @@ -7,15 +7,16 @@ module ActiveSupport module ClassMethods def memoize(symbol) original_method = "_unmemoized_#{symbol}" + memoized_ivar = "@_memoized_#{symbol}" raise "Already memoized #{symbol}" if instance_methods.map(&:to_s).include?(original_method) alias_method original_method, symbol class_eval <<-EOS, __FILE__, __LINE__ def #{symbol} - if defined? @#{symbol} - @#{symbol} + if defined? #{memoized_ivar} + #{memoized_ivar} else - @#{symbol} = #{original_method} + #{memoized_ivar} = #{original_method} end end EOS |