Inum(enumerated type of Integer) provide a java-Enum-like.
Clone or download
Latest commit 41a504a Jun 29, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Refactor inum. Jun 29, 2017
spec Refactor inum. Jun 29, 2017
vendor support rails5.1 and ruby2.4 Jun 18, 2017
.coveralls.yml Add coveralls and Fix Jun 26, 2017
.gitignore fix spec. Jul 3, 2016
.travis.yml support rails5.1 and ruby2.4 Jun 18, 2017
Gemfile fix spec. Jul 3, 2016
LICENSE.txt First commit. Nov 25, 2013 Refactor inum. Jun 29, 2017
Rakefile First commit. Nov 25, 2013
inum.gemspec Add coveralls and Fix Jun 26, 2017


Inum(enumerated type of Integer) provide a Java-enum-like Enum. Inum has a function to localize by i18n.

Build Status Coverage Status Code Climate


Add this line to your application's Gemfile:

gem 'inum'

And then execute:

$ bundle

Or install it yourself as:

$ gem install inum


Define Enum(Inum)

For example create enum(inum) of Japanese Anime.

class AnimeTypes < Inum::Base
  define :EVANGELION, 0
  define :HARUHI,     1
  define :NYARUKO,    2

If the value(integer) is omitted, It is auto-incremented.(deprecated.)

Use Enum(Inum)

How to use Enum(Inum).

p AnimeTypes::EVANGELION.label      # => :EVANGELION
p AnimeTypes::EVANGELION.to_s       # => "EVANGELION"
p AnimeTypes::EVANGELION.downcase   # => "evangelion"
p AnimeTypes::EVANGELION.underscore # => "evangelion"
p AnimeTypes::EVANGELION.upcase     # => "EVANGELION"
p AnimeTypes::EVANGELION.value      # => 0 (can use to_i.)
p AnimeTypes::EVANGELION.translate  # => エヴァンゲリオン (I18n.t will be called with `anime_types.evangelion`.)

# Parse object.
# This method is parsable Symbol and String and Integer and Self.
p AnimeTypes.parse(1) # => AnimeTypes::HARUHI

# Compare object.
p AnimeTypes::HARUHI.eql?('HARUHI')   # => true (This method can compare all parsable object.)

# each method.
AnimeTypes.each {|enum| p enum}

# Get length
AnimeTypes.length # => 3

# Get labels and values
AnimeTypes.labels # => [:EVANGELION, :HARUHI, :NYARUKO]
AnimeTypes.values # => [0, 1, 2]

# Get form items.
AnimeTypes.form_items # => [['エヴァンゲリオン', 'EVANGELION'], ['涼宮ハルヒの憂鬱', 'HARUHI'], ....]

# form_items usually use with some rails view helpers.
# :name, Enum.form_items
# :name, Enum.form_items(except:[:EVANGELION])
# :name, Enum.form_items(only:[:EVANGELION])

can use Enumerable and Comparable.

If use ActiveRecord, can use bind_inum

class Favorite < ActiveRecord::Base
  bind_inum :anime, AnimeTypes

bind_enum wrap accessor of column.

fav = AnimeTypes::NYARUKO)

# #getter will return instance of AnimeTypes.
p fav.anime.t # => '這いよれ!ニャル子さん' t is aliased translate.

# #setter can set parsable object.
anime.type = 1
anime.type = '1'
anime.type = 'NYARUKO'

# check methods.
p fav.anime_evangelion? # => false


translate methods localize enum by i18n. default i18n key is #{name_space}.#{class_name}.#{label}.

    evangelion: 'エヴァンゲリオン'
    haruhi:     'ハルヒ'
    nyaruko:    '這いよれ!ニャル子さん'

If you want to change key of i18n, Override i18n_key class method.

class AnimeTypes < Inum::Base
  def self.i18n_key(underscore_class_path, underscore_label)



  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


$ bundle exec rspec