method

define_attribute

Importance_2
v6.0.0 - Show latest stable - 0 notes - Class: ClassMethods
define_attribute( name, cast_type, default: NO_DEFAULT_PROVIDED, user_provided_default: true ) public

This is the low level API which sits beneath attribute. It only accepts type objects, and will do its work immediately instead of waiting for the schema to load. Automatic schema detection and ClassMethods#attribute both call this under the hood. While this method is provided so it can be used by plugin authors, application code should probably use ClassMethods#attribute.

name The name of the attribute being defined. Expected to be a String.

cast_type The type object to use for this attribute.

default The default value to use when no value is provided. If this option is not passed, the previous default value (if any) will be used. Otherwise, the default will be nil. A proc can also be passed, and will be called once each time a new value is needed.

user_provided_default Whether the default value should be cast using cast or deserialize.

Show source
Register or log in to add new notes.