0.0
No commit activity in last 3 years
No release in over 3 years
Easy way to add enums
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.13.0

Runtime

~> 3.2.0
 Project Readme

JiffyEnums

Gem Version Build Status Code Climate

Java-style enums brought over to Ruby and CoffeeScript

Installation

Add this line to your application's Gemfile:

gem 'jiffy_enums'

And then execute:

$ bundle

Usage

In Ruby

Class MyEnums < JiffyEnums
  define :ENUM1, 'enum 1'
  define :ENUM2, 'enum 2'
  define :ENUM3, 'enum 3'
end

MyEnums[:ENUM1].key
=> :ENUM1
MyEnums[:ENUM1].value
=> "enum 1"
MyEnums[:ENUM1].ordinal
=> 1

MyEnums::ENUM2
=> "enum 2"

In CoffeeScript (e.g. in a Rails View)

Enums = {}
<%= MyEnums.to_coffee('Enums') %>

Enums.MyEnums.get('ENUM1').key
=> "ENUM1"
Enums.MyEnums.get('ENUM1').value
=> "enum 1"
Enums.MyEnums.get('ENUM1').ordinal
=> 1
=>

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request