Literal
Basic Usage
Mixin
class User
include Literal
attribute :name, String
attribute :age, Integer
end
Struct
class Person < Literal::Struct
attribute :name, String
attribute :age, Integer
end
Data
class Person < Literal::Data
attribute :name, String
attribute :age, Integer
end
Special Types
Union
_Union(String, Symbol)
Boolean
_Boolean
Maybe
_Maybe(String)
Array
_Array(String)
Set
_Set(String)
Enumerable
_Enumerable(String)
Tuple
An Enumerable containing exactly the specified types in order.
_Tuple(String, Integer)
Hash
_Hash(String, Integer)
Interface
_Interface(:to_s)
Class
_Class(RuntimeError)
Module
_Module(Enumerable)
Integer
You can of course just use Integer
to specify an integer type. The special type _Integer
allows you to limit that type with a range, while verifying that it's an integer and not something else that matches the range such as a float.
_Integer(18..)
You can use these types together.
_Maybe(Union(String, Symbol, Interface(:to_s), Interface(:to_str), Tuple(String, Symbol)))