跳至内容 跳至搜索

Active Record 属性方法 读取

方法
R

实例公共方法

read_attribute(attr_name, &block)

返回由 attr_name 标识的属性的值,该值在经过类型转换后返回。例如,一个日期属性会将 “2004-12-12” 转换为 Date.new(2004, 12, 12)。(有关特定类型转换行为的信息,请参阅 ActiveModel::Type 下的类型。)

# File activerecord/lib/active_record/attribute_methods/read.rb, line 29
def read_attribute(attr_name, &block)
  name = attr_name.to_s
  name = self.class.attribute_aliases[name] || name

  @attributes.fetch_value(name, &block)
end