diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-07-14 20:25:09 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-14 20:25:09 -0500 |
commit | 7f0346237e30e55d6cd16a8b4a9dfe4193f61804 (patch) | |
tree | 260d59fad3df5eeeedcbf4e145ffc115100ffcfb /activesupport/lib | |
parent | 911c2c381347ffb04615896ee6afe45277eeb103 (diff) | |
download | rails-7f0346237e30e55d6cd16a8b4a9dfe4193f61804.tar.gz rails-7f0346237e30e55d6cd16a8b4a9dfe4193f61804.tar.bz2 rails-7f0346237e30e55d6cd16a8b4a9dfe4193f61804.zip |
Append a "_" to memoized instance variables
Diffstat (limited to 'activesupport/lib')
-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 |