1
0
Fork 0
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:
Carlos Antonio da Silva 2012-06-25 15:06:11 -03:00
parent 7fad77fcc7
commit 4a20fcf7b2

View file

@ -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