aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorEugene Pimenov <libc@mac.com>2008-10-05 17:24:52 -0500
committerJoshua Peek <josh@joshpeek.com>2008-10-05 17:25:58 -0500
commit8603813ac6e1bff8d3addad58d0a56b33baafc59 (patch)
tree05e41813fde44b811bc69a4a87f63e74420c5913 /activesupport/lib
parent1c75b4fd42c707ce3d539e8453784b4abf74e035 (diff)
downloadrails-8603813ac6e1bff8d3addad58d0a56b33baafc59.tar.gz
rails-8603813ac6e1bff8d3addad58d0a56b33baafc59.tar.bz2
rails-8603813ac6e1bff8d3addad58d0a56b33baafc59.zip
Fix memoize_all for methods with punctuation [#1175 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/memoizable.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb
index 4786fd6e0b..cd5c01cda2 100644
--- a/activesupport/lib/active_support/memoizable.rb
+++ b/activesupport/lib/active_support/memoizable.rb
@@ -1,5 +1,9 @@
module ActiveSupport
module Memoizable
+ MEMOIZED_IVAR = Proc.new do |symbol|
+ "@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
+ end
+
module Freezable
def self.included(base)
base.class_eval do
@@ -20,7 +24,7 @@ module ActiveSupport
if method(m).arity == 0
__send__($1)
else
- ivar = :"@_memoized_#{$1}"
+ ivar = MEMOIZED_IVAR.call($1)
instance_variable_set(ivar, {})
end
end
@@ -30,7 +34,7 @@ module ActiveSupport
def unmemoize_all
methods.each do |m|
if m.to_s =~ /^_unmemoized_(.*)/
- ivar = :"@_memoized_#{$1}"
+ ivar = MEMOIZED_IVAR.call($1)
instance_variable_get(ivar).clear if instance_variable_defined?(ivar)
end
end
@@ -40,7 +44,7 @@ module ActiveSupport
def memoize(*symbols)
symbols.each do |symbol|
original_method = :"_unmemoized_#{symbol}"
- memoized_ivar = :"@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}"
+ memoized_ivar = MEMOIZED_IVAR.call(symbol)
class_eval <<-EOS, __FILE__, __LINE__
include Freezable