aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/memoizable.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-07-14 20:25:09 -0500
committerJoshua Peek <josh@joshpeek.com>2008-07-14 20:25:09 -0500
commit7f0346237e30e55d6cd16a8b4a9dfe4193f61804 (patch)
tree260d59fad3df5eeeedcbf4e145ffc115100ffcfb /activesupport/lib/active_support/memoizable.rb
parent911c2c381347ffb04615896ee6afe45277eeb103 (diff)
downloadrails-7f0346237e30e55d6cd16a8b4a9dfe4193f61804.tar.gz
rails-7f0346237e30e55d6cd16a8b4a9dfe4193f61804.tar.bz2
rails-7f0346237e30e55d6cd16a8b4a9dfe4193f61804.zip
Append a "_" to memoized instance variables
Diffstat (limited to 'activesupport/lib/active_support/memoizable.rb')
-rw-r--r--activesupport/lib/active_support/memoizable.rb7
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