module Fried::Schema::Struct::ClassMethods
Constants
- Noop
Public Instance Methods
attribute(name, type, default: Noop)
click to toggle source
Defines an attr_accessor with given name, type checking and optional default value @param name [Symbol, String] name for attribute (attr_accessor) @param type [::Fried::Typings::Type, Class, Module] either a `Type`
from `Fried::Typings` (even a custom one) or any `Class` or `Module`
@param default [Object, Proc] if an object is passed, it will be used
as default. If a {Proc} is passed, it will be evaluated during
object initialization
@return [Symbol] reader method name
# File lib/fried/schema/struct.rb, line 35 def attribute(name, type, default: Noop) schema = CreateDefinitionIfMissing.(self) definer = Attribute::Definition attribute_definition = definer.new(name, type, default) schema.add_attribute(attribute_definition) Attribute::DefineMethods.(attribute_definition, self) end