diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-25 15:06:11 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-06-26 22:21:19 -0300 |
commit | 4a20fcf7b2f26da3cb41f71d83f86d1c21fe9f22 (patch) | |
tree | cdd74dd17d714c3319bfb3b47db4d756d9712f41 /activemodel | |
parent | 7fad77fcc7a986bd11f386fcc877ed9b0bce47d1 (diff) | |
download | rails-4a20fcf7b2f26da3cb41f71d83f86d1c21fe9f22.tar.gz rails-4a20fcf7b2f26da3cb41f71d83f86d1c21fe9f22.tar.bz2 rails-4a20fcf7b2f26da3cb41f71d83f86d1c21fe9f22.zip |
Refactor attribute method matcher to use Hash#fetch
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index de8c264221..eb06250060 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -335,15 +335,13 @@ module ActiveModel end def attribute_method_matcher(method_name) #:nodoc: - if attribute_method_matchers_cache.key?(method_name) - attribute_method_matchers_cache[method_name] - else + attribute_method_matchers_cache.fetch(method_name) do |name| # Must try to match prefixes/suffixes first, or else the matcher with no prefix/suffix # will match every time. matchers = attribute_method_matchers.partition(&:plain?).reverse.flatten(1) match = nil - matchers.detect { |method| match = method.match(method_name) } - attribute_method_matchers_cache[method_name] = match + matchers.detect { |method| match = method.match(name) } + attribute_method_matchers_cache[name] = match end end |