Add enumeration to your ruby classes
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.coveralls.yml
.gitignore
.travis.yml
Gemfile
LICENSE.md
README.md
Rakefile
act_as_enumerable.gemspec
init.rb

README.md

ActAsEnumerable

Build Status Coveralls Dependency Status Code Climate Gem Version

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

  1. Fork repository
  2. Create a branch following a successfull branching model
  3. Write your feature/fix
  4. Write tests
  5. Pull request

Licence

Released under the MIT License. See the LICENSE file for further details.