Method: ActiveRecord::AttributeMethods#read_attribute

Defined in:
lib/active_record/attribute_methods.rb

#read_attribute(attr_name) ⇒ Object

Returns the value of the attribute identified by attr_name after it has been typecast (for example, “2004-12-12” in a data column is cast to a date object, like Date.new(2004, 12, 12)).



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/active_record/attribute_methods.rb', line 266

def read_attribute(attr_name)
  attr_name = attr_name.to_s
  if !(value = @attributes[attr_name]).nil?
    if column = column_for_attribute(attr_name)
      if unserializable_attribute?(attr_name, column)
        unserialize_attribute(attr_name)
      else
        column.type_cast(value)
      end
    else
      value
    end
  else
    nil
  end
end