Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor attribute method matcher to use Hash#fetch

  • Loading branch information...
commit 4a20fcf7b2f26da3cb41f71d83f86d1c21fe9f22 1 parent 7fad77f
@carlosantoniodasilva carlosantoniodasilva authored
Showing with 3 additions and 5 deletions.
  1. +3 −5 activemodel/lib/active_model/attribute_methods.rb
View
8 activemodel/lib/active_model/attribute_methods.rb
@@ -335,15 +335,13 @@ def attribute_method_matchers_cache #:nodoc:
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
Please sign in to comment.
Something went wrong with that request. Please try again.