略過內容 略過搜尋

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