instance method
attribute
Ruby on Rails 6.0.6
Since v5.2.8.1Signature
attribute(name, type = Type::Value.new, **options)
No documentation comment.
Parameters
-
namereq -
typeopt = Type::Value.new -
optionskeyrest
Source
# File activemodel/lib/active_model/attributes.rb, line 19
def attribute(name, type = Type::Value.new, **options)
name = name.to_s
if type.is_a?(Symbol)
type = ActiveModel::Type.lookup(type, **options.except(:default))
end
self.attribute_types = attribute_types.merge(name => type)
define_default_attribute(name, options.fetch(:default, NO_DEFAULT_PROVIDED), type)
define_attribute_method(name)
end
Defined in activemodel/lib/active_model/attributes.rb line 19
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Attributes::ClassMethods