ActAsEnumerable
Add enumeration to your ruby classes
Installation
gem install act_as_enumerable
Or in your Gemfile:
gem 'act_as_enumerable'
Usage
class Person
attr_accessor :gender
def initialize opts
@gender = opts[:gender]
end
enum :gender, %w(male female)
end
cameron = Person.new gender: :male
p Person.gender_values
#=> ['male', 'female']
p Person.gender_captions
#=> ['Male', 'Female']
p cameron.gender
#=> 'male'
p cameron.male?
#=> true
p cameron.female?
#=> false
p cameron.female!
#=> 'female'
p cameron.male?
#=> false
p cameron.female?
#=> true
p cameron.gender_caption
#=> 'Female'
Contributing
- Fork repository
- Create a branch following a successfull branching model
- Write your feature/fix
- Write tests
- Pull request
Licence
Released under the MIT License. See the LICENSE file for further details.