Этот метод отвечает за type_cast
в активной записи
def type_cast(value)
return nil if value.nil?
return coder.load(value) if encoded?
klass = self.class
case type
when :string, :text then value
when :integer then klass.value_to_integer(value)
when :float then value.to_f
when :decimal then klass.value_to_decimal(value)
when :datetime, :timestamp then klass.string_to_time(value)
when :time then klass.string_to_dummy_time(value)
when :date then klass.value_to_date(value)
when :binary then klass.binary_to_string(value)
when :boolean then klass.value_to_boolean(value)
else value
end
end
Чтобы понять rails
activerecord
type_cast
в деталях, пожалуйста, посетите эти три участка
1) Thoughtbot блог How Rails' Type Casting Works
2) Ken Collins ActiveRecord 4.2's Type Casting
3) Рельсы activerecord
метод-метод в github