From 4a20fcf7b2f26da3cb41f71d83f86d1c21fe9f22 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 25 Jun 2012 15:06:11 -0300 Subject: Refactor attribute method matcher to use Hash#fetch --- activemodel/lib/active_model/attribute_methods.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'activemodel') 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 -- cgit v1.2.3