Rubenum

Enum implementation for Ruby.

Create an enum from an array of strings with Rubenum.new.
Only valid Ruby identifiers are accepted.
Every element will be capitalized in order to make them Ruby constants.

Arguments

  • elements (array of string) : array containing the elements of the enum
  • upcase (boolean optional default:false) : true to upcase elements instead of capitalize them
  • binary_values (boolean optional default:false) : true to use binary values (1 2 4 8 16 ...) instead of incremental values (1 2 3 4 5 ...)

Example

e = Rubenum.new(%w[red orange green])
puts e::Orange   # => 2