0.0
No release in over 3 years
Low commit activity in last 3 years
Struct classes with safer constructors.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.0
>= 0
 Project Readme

SafeValues

Build Status

Value generates Struct classes with safer constructors. It is designed to provide a superset of the interface of the Values gem, with better performance, by subclassing actual native Structs.

Value constructors require all mandatory arguments to be provided, and supply default values for all optional arguments. Additionally, the resulting instance is frozen. To obtain a mutable Value, use dup.

Value types are created similarly to Structs, with the addition that optional arguments are may be specified as keyword arguments:

ValueType = Value.new(:a, :b, c: default_value)

The default values to optional arguments are saved at class creation time and supplied as default constructor arguments to instances. Default values are aliased, so providing mutable defaults is discouraged.

Two instance constructors are provided, with positional and keyword arguments.

Value types may be constructed with positional arguments using new. Arguments are provided in the same order as specified at class initialization time, with mandatory arguments before optional ones. For example:

ValueType.new(1, 2) or ValueType.new(1, 2, 3)

Value types may be constructed with keyword arguments using with. For example:

ValueType.with(a: 1, b: 2) or ValueType.with(a: 1, b: 2, c: 3)