Skip to content
This repository
Browse code

Refactor attribute method matcher to use Hash#fetch

  • Loading branch information...
commit 4a20fcf7b2f26da3cb41f71d83f86d1c21fe9f22 1 parent 7fad77f
Carlos Antonio da Silva authored June 25, 2012
8  activemodel/lib/active_model/attribute_methods.rb
@@ -335,15 +335,13 @@ def attribute_method_matchers_cache #:nodoc:
335 335
         end
336 336
 
337 337
         def attribute_method_matcher(method_name) #:nodoc:
338  
-          if attribute_method_matchers_cache.key?(method_name)
339  
-            attribute_method_matchers_cache[method_name]
340  
-          else
  338
+          attribute_method_matchers_cache.fetch(method_name) do |name|
341 339
             # Must try to match prefixes/suffixes first, or else the matcher with no prefix/suffix
342 340
             # will match every time.
343 341
             matchers = attribute_method_matchers.partition(&:plain?).reverse.flatten(1)
344 342
             match = nil
345  
-            matchers.detect { |method| match = method.match(method_name) }
346  
-            attribute_method_matchers_cache[method_name] = match
  343
+            matchers.detect { |method| match = method.match(name) }
  344
+            attribute_method_matchers_cache[name] = match
347 345
           end
348 346
         end
349 347
 

0 notes on commit 4a20fcf

Please sign in to comment.
Something went wrong with that request. Please try again.