Enum Plus
Add enumeration to your ruby classes
Installation
gem install enum_plus
Or in your Gemfile:
gem 'enum_plus'
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.
#=> ['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.
#=> '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.