diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-08-07 23:31:43 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-08-07 23:31:43 -0700 |
commit | 6c70c02c83b3a03c88df4286130be8882f6d201c (patch) | |
tree | f0529f50df45893b20a8d5c006f3156e645db67b | |
parent | a8057669ff6ba11e228fc73eef7390b826d0de25 (diff) | |
download | rails-6c70c02c83b3a03c88df4286130be8882f6d201c.tar.gz rails-6c70c02c83b3a03c88df4286130be8882f6d201c.tar.bz2 rails-6c70c02c83b3a03c88df4286130be8882f6d201c.zip |
Freeze memoized results when instance is frozen instead of immediately so you can memoize mutable objects
-rw-r--r-- | activesupport/lib/active_support/memoizable.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb index e6049d9496..b5adc2330c 100644 --- a/activesupport/lib/active_support/memoizable.rb +++ b/activesupport/lib/active_support/memoizable.rb @@ -14,7 +14,7 @@ module ActiveSupport methods.each do |method| if method.to_s =~ /^_unmemoized_(.*)/ begin - __send__($1) + __send__($1).freeze rescue ArgumentError end end @@ -41,7 +41,7 @@ module ActiveSupport if !reload && defined? #{memoized_ivar} #{memoized_ivar} else - #{memoized_ivar} = #{original_method}.freeze + #{memoized_ivar} = #{original_method} end end else @@ -52,7 +52,7 @@ module ActiveSupport if !reload && #{memoized_ivar} && #{memoized_ivar}.has_key?(args) #{memoized_ivar}[args] else - #{memoized_ivar}[args] = #{original_method}(*args).freeze + #{memoized_ivar}[args] = #{original_method}(*args) end end end |