Methods
Instance Public methods
attribute(name, cast_type = nil, default: nil, **options) Link
Defines a model attribute. In addition to the attribute name, a cast type and default value may be specified, as well as any options supported by the given cast type.
class Person
include ActiveModel::Attributes
attribute :name, :string
attribute :active, :boolean, default: true
end
person = Person.new
person.name = "Volmer"
person.name # => "Volmer"
person.active # => true
attribute_names() Link
Returns an array of attribute names as strings.
class Person
include ActiveModel::Attributes
attribute :name, :string
attribute :age, :integer
end
Person.attribute_names # => ["name", "age"]
type_for_attribute(attribute_name, &block) Link
Returns the type of the specified attribute after applying any modifiers. This method is the only valid source of information for anything related to the types of a model’s attributes. The return value of this method will implement the interface described by ActiveModel::Type::Value
(though the object itself may not subclass it).
Source: on GitHub
# File activemodel/lib/active_model/attributes.rb, line 79