JiffyEnums
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
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request