Attribute accessors with validation options so you notice when something is wrong earlier.
class Foo
extend ValidatedAccessors
validated_accessor :bar, valid: [:foo, :bar]
# a transformation can be applied to the accessor for consistency
validated_accessor(:age, valid: (18..100)) { |a| a.to_i }
end
foo = Foo.new
foo.bar = :foo # => error
foo.age = '24'
foo.age # => 24
And you can read the docs.
- Fork it ( https://github.com/[my-github-username]/validated_accessors/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request