# SmartCore::Types · [![Gem Version](https://badge.fury.io/rb/smart_types.svg)](https://badge.fury.io/rb/smart_types) > A set of objects that acts like types (type checking and type casting) with a support for basic type algebra. Minimalistic type system for any ruby project. Supports custom type definitioning, type validation, type casting and type categorizing. Provides a set of commonly used type categories and general purpose types. Has a flexible and simplest type definition toolchain. ## Installation ```ruby gem 'smart_types' ``` ```shell bundle install # --- or --- gem install smart_types ``` ```ruby require 'smart_core/types' ``` --- ## Usage - [Type interface](#type-interface) - [Basic type algebra](#basic-type-algebra) - [Supported types](#supported-types) - [Nilable types](#nilable-types) - [Custom type definition](#custom-type-definition) - [Primitive type definition](#primitive-type-definition) - [With type invariants](#with-type-invariants) - [Type validation](#type-validation) - [Type casting](#type-casting) - [Roadmap](#roadmap) - [Contributing](#contributing) - [Build](#build) - [License](#license) - [Authors](#authors) --- ## Type Interface ```ruby # documentation is coming type.valid?(value) type.validate!(value) type.cast(value) type.nilable type3 = type1 | type2 type4 = type1 & type2 ``` Types with runtime: ```ruby # get a type object with a custom runtime (instances of String or Symbol): type = SmartCore::Types::Protocol::InstanceOf(::String, ::Symbol) type.valid?(:test) # => true type.valid?('test') # => true type.valid?(123.456) # => false # another type object with a custom runtime (tuple (String, Integer, Time)): type = SmartCore::Types::Variadic::Tuple(::String, ::Integer, ::DateTime) type.valid?(['test', 1, DateTime.new]) # => true type.valid?([:test, 2]) # => false ``` ## Supported types - Primitives ```ruby SmartCore::Types::Value::Any SmartCore::Types::Value::Nil SmartCore::Types::Value::String SmartCore::Types::Value::Symbol SmartCore::Types::Value::Text SmartCore::Types::Value::Integer SmartCore::Types::Value::Float SmartCore::Types::Value::Numeric SmartCore::Types::Value::BigDecimal SmartCore::Types::Value::Boolean SmartCore::Types::Value::Array SmartCore::Types::Value::Set SmartCore::Types::Value::Hash SmartCore::Types::Value::Proc SmartCore::Types::Value::Class SmartCore::Types::Value::Module SmartCore::Types::Value::Time SmartCore::Types::Value::DateTime SmartCore::Types::Value::Date SmartCore::Types::Value::TimeBased ``` - Protocols: ```ruby SmartCore::Types::Protocol::InstanceOf ``` ```ruby # examples (SmartCore::Types::Protocol::InstanceOf): SmartCore::Types::Protocol::InstanceOf(::Integer) # only integer SmartCore::Types::Protocol::InstanceOf(::String, ::Symbol) # string or symbol SmartCore::Types::Protocol::InstanceOf(::Time, ::DateTime, ::Date) # time or datetime or date ``` - Variadic: ```ruby SmartCore::Types::Variadic::Tuple ``` ```ruby # examples (SmartCore::Types::Variadic::Tuple): SmartCore::Types::Variadic::Tuple(::String, ::Integer, ::Time) # array with signature [, ,