mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor attribute method matcher to use Hash#fetch
This commit is contained in:
parent
7fad77fcc7
commit
4a20fcf7b2
1 changed files with 3 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue