aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-07-15 00:04:30 +0900
committerkennyj <kennyj@gmail.com>2012-07-15 00:04:30 +0900
commit088022ef262cc43318651cf7bd68e6eb4b5475f6 (patch)
tree50b960d022af999c37a4c7e85e309d791e12021f
parent9b7401b23d7f82781084086bac903849294e7c7f (diff)
downloadrails-088022ef262cc43318651cf7bd68e6eb4b5475f6.tar.gz
rails-088022ef262cc43318651cf7bd68e6eb4b5475f6.tar.bz2
rails-088022ef262cc43318651cf7bd68e6eb4b5475f6.zip
Avoid to call send(store_attribute) twice.
-rw-r--r--activerecord/lib/active_record/store.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/store.rb b/activerecord/lib/active_record/store.rb
index 990a1b78ed..81576e7cd3 100644
--- a/activerecord/lib/active_record/store.rb
+++ b/activerecord/lib/active_record/store.rb
@@ -57,8 +57,7 @@ module ActiveRecord
keys = keys.flatten
keys.each do |key|
define_method("#{key}=") do |value|
- initialize_store_attribute(store_attribute)
- attribute = send(store_attribute)
+ attribute = initialize_store_attribute(store_attribute)
if value != attribute[key]
attribute[key] = value
send :"#{store_attribute}_will_change!"
@@ -66,8 +65,7 @@ module ActiveRecord
end
define_method(key) do
- initialize_store_attribute(store_attribute)
- send(store_attribute)[key]
+ initialize_store_attribute(store_attribute)[key]
end
end
@@ -77,8 +75,12 @@ module ActiveRecord
private
def initialize_store_attribute(store_attribute)
- attr = send(store_attribute)
- send :"#{store_attribute}=", IndifferentCoder.as_indifferent_hash(attr) unless attr.is_a?(HashWithIndifferentAccess)
+ attribute = send(store_attribute)
+ unless attribute.is_a?(HashWithIndifferentAccess)
+ attribute = IndifferentCoder.as_indifferent_hash(attribute)
+ send :"#{store_attribute}=", attribute
+ end
+ attribute
end
class IndifferentCoder