Predicates are truth accessors for your Ruby classes and models. Yep, that's about it.
Extend your class or model with Predicates and define the predicate by supplying an attribute:
require 'predicates'
class User
extend Predicates
attr_accessor :confirmed
predicate :confirmed?
end
user = User.new
user.confirmed = 1
user.confirmed? #=> true
Predicates will also create an attribute writer for you using attr_writer if the attribute you supplied has not been predefined.
class User
extend Predicates
predicate :confirmed?
end
user = User.new
user.confirmed = 1
user.confirmed? #=> true
Add this line to your application's Gemfile:
gem 'predicates'
And then execute:
$ bundle
Or install it yourself as:
$ gem install predicates
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Create tests and make them pass (
rake test) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request