Adds accessors (using type_constraints) to Module class.
require 'scottie'
require 'type_constraints'
TypeConstraints.setup do
subtype :NotNgWord, :String do
constraint -> v { v !~ /悪/ }
end
end
class Person
has name: :NotNgWord, twitter_acount: :String
end
# ok
person = Person.new
person.name = "ひさいち"
person.twitter_acount = "hisaichi5518"
# throw exception
# person.name = "悪魔ちゃん"
# person.twitter_acount = :hisaichi5518
# ok
p person.name #=> "ひさいち"
p person.twitter_acount #=> "hisaichi5518"
Add this line to your application's Gemfile:
gem 'scottie'
And then execute:
$ bundle
Or install it yourself as:
$ gem install scottie
- Fork it ( https://github.com/hisaichi5518/scottie/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