0.0
No commit activity in last 3 years
No release in over 3 years
Type guess struct
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.11
~> 10.0
>= 0
 Project Readme

GuessStruct

Struct class that guess attributes type.

A = GuessStruct.new(:foo, :bar, :baz)
A.definition #=> {:foo=>nil, :bar=>nil, :baz=>nil}
a = A.new(foo: 1)
A.definition #=> {:foo=>Fixnum, :bar=>nil, :baz=>nil}
a.foo #=> 1
a.to_h #=> {:foo => 1, :bar => nil, :baz => nil}
a.foo = 'a' #=> GuessStruct::GuessError: A#foo expect Fixnum got "a"

# allow nil input. But not clear defined type.
a.foo = nil
A.definition #=> {:foo=>Fixnum, :bar=>nil, :baz=>nil}

# share guess type in class
A.new(foo: :sym) #=> GuessStruct::GuessError: A#foo expect Fixnum got "a"
A.new(foo: 10) #=> #<A foo=10, bar=nil, baz=nil>

Installation

Add this line to your application's Gemfile:

gem 'guess_struct'

And then execute:

$ bundle

Or install it yourself as:

$ gem install guess_struct

License

The gem is available as open source under the terms of the MIT License.