提交 0581c1a9 编写于 作者: A Aaron Patterson

use fetch rather than both Hash#key? and Hash#[]

上级 148f849c
......@@ -92,12 +92,14 @@ def cacheable_column?(column)
end
def internal_attribute_access_code(attr_name, cast_code)
access_code = "(v=@attributes[attr_name]) && #{cast_code}"
unless attr_name == primary_key
access_code.insert(0, "missing_attribute(attr_name, caller) unless @attributes.has_key?(attr_name); ")
if attr_name == primary_key
access_code = "v = @attributes[attr_name];"
else
access_code = "v = @attributes.fetch(attr_name) { missing_attribute(attr_name, caller) };"
end
access_code << "v && #{cast_code};"
if cache_attribute?(attr_name)
access_code = "@attributes_cache[attr_name] ||= (#{access_code})"
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册