<p>What's the best way to implement the enum idiom in Ruby? I'm looking for something which I can use (almost) like the Java/C# enums.</p>

[{'answer_id': 75787, 'author': 'Jan Krüger', 'author_id': 12471, 'author_profile': 'https://Stackoverflow.com/users/12471', 'pm_score': 1, 'selected': False, 'text': "<p>Most people use symbols (that's the <code>:foo_bar</code> syntax). They're sort of unique opaque values. Symbols don't belong to any enum-style type so they're not really a faithful representation of C's enum type but this is pretty much as good as it gets.</p>\n"}, {'answer_id': 75801, 'author': 'emk', 'author_id': 12089, 'author_profile': 'https://Stackoverflow.com/users/12089', 'pm_score': 6, 'selected': False, 'text': "<p>The most idiomatic way to do this is to use symbols.  For example, instead of:</p>\n\n<pre><code>enum {\n  FOO,\n  BAR,\n  BAZ\n}\n\nmyFunc(FOO);\n</code></pre>\n\n<p>...you can just use symbols:</p>\n\n<pre><code># You don't actually need to declare these, of course--this is\n# just to show you what symbols look like.\n:foo\n:bar\n:baz\n\nmy_func(:foo)\n</code></pre>\n\n<p>This is a bit more open-ended than enums, but it fits well with the Ruby spirit.</p>\n\n<p>Symbols also perform very well. Comparing two symbols for equality, for example, is much faster than comparing two strings.</p>\n"}, {'answer_id': 76046, 'author': 'mlibby', 'author_id': 13468, 'author_profile': 'https://Stackoverflow.com/users/13468', 'pm_score': 9, 'selected': True, 'text': '<p>Two ways. Symbols (<code>:foo</code> notation) or constants (<code>FOO</code> notation).</p>\n<p>Symbols are appropriate when you want to enhance readability without littering code with literal strings.</p>\n<pre><code>postal_code[:minnesota] = &quot;MN&quot;\npostal_code[:new_york] = &quot;NY&quot;\n</code></pre>\n<p>Constants are appropriate when you have an underlying value that is important. Just declare a module to hold your constants and then declare the constants within that.</p>\n<pre><code>module Foo\n  BAR = 1\n  BAZ = 2\n  BIZ = 4\nend\n \nflags = Foo::BAR | Foo::BAZ # flags = 3\n</code></pre>\n<p>Added 2021-01-17</p>\n<p>If you are passing the enum value around (for example, storing it in a database) and you need to be able to translate the value back into the symbol, there\'s a mashup of both approaches</p>\n<pre><code>COMMODITY_TYPE = {\n  currency: 1,\n  investment: 2,\n}\n\ndef commodity_type_string(value)\n  COMMODITY_TYPE.key(value)\nend\n\nCOMMODITY_TYPE[:currency]\n</code></pre>\n<p>This approach inspired by andrew-grimm\'s answer <a href="https://stackoverflow.com/a/5332950/13468">https://stackoverflow.com/a/5332950/13468</a></p>\n<p>I\'d also recommend reading through the rest of the answers here since there are a lot of ways to solve this and it really boils down to what it is about the other language\'s enum that you care about</p>\n'}, {'answer_id': 76722, 'author': 'mislav', 'author_id': 11687, 'author_profile': 'https://Stackoverflow.com/users/11687', 'pm_score': 2, 'selected': False, 'text': '<p>It all depends how you use Java or C# enums. How you use it will dictate the solution you\'ll choose in Ruby.</p>\n\n<p>Try the native <code>Set</code> type, for instance:</p>\n\n<pre><code>&gt;&gt; enum = Set[\'a\', \'b\', \'c\']\n=&gt; #&lt;Set: {"a", "b", "c"}&gt;\n&gt;&gt; enum.member? "b"\n=&gt; true\n&gt;&gt; enum.member? "d"\n=&gt; false\n&gt;&gt; enum.add? "b"\n=&gt; nil\n&gt;&gt; enum.add? "d"\n=&gt; #&lt;Set: {"a", "b", "c", "d"}&gt;\n</code></pre>\n'}, {'answer_id': 164514, 'author': 'Jonke', 'author_id': 15638, 'author_profile': 'https://Stackoverflow.com/users/15638', 'pm_score': 2, 'selected': False, 'text': "<p>Symbols is the ruby way. However, sometimes one need to talk to some C code or something or Java that expose some enum for various things.</p>\n\n<hr>\n\n<pre><code>#server_roles.rb\nmodule EnumLike\n\n  def EnumLike.server_role\n    server_Symb=[ :SERVER_CLOUD, :SERVER_DESKTOP, :SERVER_WORKSTATION]\n    server_Enum=Hash.new\n    i=0\n    server_Symb.each{ |e| server_Enum[e]=i; i +=1}\n    return server_Symb,server_Enum\n  end\n\nend\n</code></pre>\n\n<hr>\n\n<p>This can then be used like this</p>\n\n<hr>\n\n<pre><code>require 'server_roles'\n\nsSymb, sEnum =EnumLike.server_role()\n\nforeignvec[sEnum[:SERVER_WORKSTATION]]=8\n</code></pre>\n\n<hr>\n\n<p>This is can of course be made abstract and you can roll our own Enum class </p>\n"}, {'answer_id': 612357, 'author': 'dlamblin', 'author_id': 459, 'author_profile': 'https://Stackoverflow.com/users/459', 'pm_score': 2, 'selected': False, 'text': '<p>Someone went ahead and wrote a ruby gem called <a href="http://renum.rubyforge.org/" rel="nofollow noreferrer">Renum</a>. It claims to get the closest Java/C# like behavior. Personally I\'m still learning Ruby, and I was a little shocked when I wanted to make a specific class contain a static enum, possibly a hash, that it wasn\'t exactly easily found via google.</p>\n'}, {'answer_id': 1494092, 'author': 'Philippe Monnet', 'author_id': 23308, 'author_profile': 'https://Stackoverflow.com/users/23308', 'pm_score': 0, 'selected': False, 'text': '<p>Another approach is to use a Ruby class with a hash containing names and values as described in the following <a href="http://www.rubyfleebie.com/enumerations-and-ruby/" rel="nofollow noreferrer">RubyFleebie blog post</a>. This allows you to convert easily between values and constants (especially if you add a class method to lookup the name for a given value).</p>\n'}, {'answer_id': 2573093, 'author': 'goreorto', 'author_id': 308517, 'author_profile': 'https://Stackoverflow.com/users/308517', 'pm_score': 0, 'selected': False, 'text': "<p>I think the best way to implement enumeration like types is with symbols since the pretty much behave as integer (when it comes to performace, object_id is used to make comparisons  ); you don't need to worry about indexing and they look really neat in your code xD</p>\n"}, {'answer_id': 5332215, 'author': 'dB.', 'author_id': 123094, 'author_profile': 'https://Stackoverflow.com/users/123094', 'pm_score': 3, 'selected': False, 'text': '<p>Check out the ruby-enum gem, <a href="https://github.com/dblock/ruby-enum" rel="noreferrer">https://github.com/dblock/ruby-enum</a>.</p>\n\n<pre><code>class Gender\n  include Enum\n\n  Gender.define :MALE, "male"\n  Gender.define :FEMALE, "female"\nend\n\nGender.all\nGender::MALE\n</code></pre>\n'}, {'answer_id': 5332950, 'author': 'Andrew Grimm', 'author_id': 38765, 'author_profile': 'https://Stackoverflow.com/users/38765', 'pm_score': 3, 'selected': False, 'text': '<p>If you\'re worried about typos with symbols, make sure your code raises an exception when you access a value with a non-existent key. You can do this by using <code>fetch</code> rather than <code>[]</code>:</p>\n\n<pre><code>my_value = my_hash.fetch(:key)\n</code></pre>\n\n<p>or by making the hash raise an exception by default if you supply a non-existent key:</p>\n\n<pre><code>my_hash = Hash.new do |hash, key|\n  raise "You tried to access using #{key.inspect} when the only keys we have are #{hash.keys.inspect}"\nend\n</code></pre>\n\n<p>If the hash already exists, you can add on exception-raising behaviour:</p>\n\n<pre><code>my_hash = Hash[[[1,2]]]\nmy_hash.default_proc = proc do |hash, key|\n  raise "You tried to access using #{key.inspect} when the only keys we have are #{hash.keys.inspect}"\nend\n</code></pre>\n\n<p>Normally, you don\'t have to worry about typo safety with constants. If you misspell a constant name, it\'ll usually raise an exception.</p>\n'}, {'answer_id': 5675566, 'author': 'Alexey', 'author_id': 126529, 'author_profile': 'https://Stackoverflow.com/users/126529', 'pm_score': 6, 'selected': False, 'text': "<p>I use the following approach:</p>\n\n<pre><code>class MyClass\n  MY_ENUM = [MY_VALUE_1 = 'value1', MY_VALUE_2 = 'value2']\nend\n</code></pre>\n\n<p>I like it for the following advantages:</p>\n\n<ol>\n<li>It groups values visually as one whole</li>\n<li>It does some compilation-time checking (in contrast with just using symbols)</li>\n<li>I can easily access the list of all possible values: just <code>MY_ENUM</code></li>\n<li>I can easily access distinct values: <code>MY_VALUE_1</code></li>\n<li>It can have values of any type, not just Symbol</li>\n</ol>\n\n<p>Symbols may be better cause you don't have to write the name of outer class, if you are using it in another class (<code>MyClass::MY_VALUE_1</code>)</p>\n"}, {'answer_id': 6170494, 'author': 'Charles', 'author_id': 48483, 'author_profile': 'https://Stackoverflow.com/users/48483', 'pm_score': 6, 'selected': False, 'text': '<p>I\'m surprised that no one has offered something like the following (harvested from the <a href="https://github.com/cstrahan/rapi/blob/master/lib/rapi.rb" rel="noreferrer">RAPI</a> gem):</p>\n\n<pre><code>class Enum\n\n  private\n\n  def self.enum_attr(name, num)\n    name = name.to_s\n\n    define_method(name + \'?\') do\n      @attrs &amp; num != 0\n    end\n\n    define_method(name + \'=\') do |set|\n      if set\n        @attrs |= num\n      else\n        @attrs &amp;= ~num\n      end\n    end\n  end\n\n  public\n\n  def initialize(attrs = 0)\n    @attrs = attrs\n  end\n\n  def to_i\n    @attrs\n  end\nend\n</code></pre>\n\n<p>Which can be used like so:</p>\n\n<pre><code>class FileAttributes &lt; Enum\n  enum_attr :readonly,       0x0001\n  enum_attr :hidden,         0x0002\n  enum_attr :system,         0x0004\n  enum_attr :directory,      0x0010\n  enum_attr :archive,        0x0020\n  enum_attr :in_rom,         0x0040\n  enum_attr :normal,         0x0080\n  enum_attr :temporary,      0x0100\n  enum_attr :sparse,         0x0200\n  enum_attr :reparse_point,  0x0400\n  enum_attr :compressed,     0x0800\n  enum_attr :rom_module,     0x2000\nend\n</code></pre>\n\n<p>Example:</p>\n\n<pre><code>&gt;&gt; example = FileAttributes.new(3)\n=&gt; #&lt;FileAttributes:0x629d90 @attrs=3&gt;\n&gt;&gt; example.readonly?\n=&gt; true\n&gt;&gt; example.hidden?\n=&gt; true\n&gt;&gt; example.system?\n=&gt; false\n&gt;&gt; example.system = true\n=&gt; true\n&gt;&gt; example.system?\n=&gt; true\n&gt;&gt; example.to_i\n=&gt; 7\n</code></pre>\n\n<p>This plays well in database scenarios, or when dealing with C style constants/enums (as is the case when using <a href="https://github.com/ffi/ffi/" rel="noreferrer">FFI</a>, which RAPI makes extensive use of).</p>\n\n<p>Also, you don\'t have to worry about typos causing silent failures, as you would with using a hash-type solution.</p>\n'}, {'answer_id': 9482922, 'author': 'Masuschi', 'author_id': 1238002, 'author_profile': 'https://Stackoverflow.com/users/1238002', 'pm_score': 2, 'selected': False, 'text': '<p>I have implemented enums like that </p>\n\n<pre><code>module EnumType\n\n  def self.find_by_id id\n    if id.instance_of? String\n      id = id.to_i\n    end \n    values.each do |type|\n      if id == type.id\n        return type\n      end\n    end\n    nil\n  end\n\n  def self.values\n    [@ENUM_1, @ENUM_2] \n  end\n\n  class Enum\n    attr_reader :id, :label\n\n    def initialize id, label\n      @id = id\n      @label = label\n    end\n  end\n\n  @ENUM_1 = Enum.new(1, "first")\n  @ENUM_2 = Enum.new(2, "second")\n\nend\n</code></pre>\n\n<p>then its easy to do operations </p>\n\n<pre><code>EnumType.ENUM_1.label\n</code></pre>\n\n<p>...</p>\n\n<pre><code>enum = EnumType.find_by_id 1\n</code></pre>\n\n<p>...</p>\n\n<pre><code>valueArray = EnumType.values\n</code></pre>\n'}, {'answer_id': 9582957, 'author': 'Anu', 'author_id': 1252072, 'author_profile': 'https://Stackoverflow.com/users/1252072', 'pm_score': 1, 'selected': False, 'text': '<pre><code>irb(main):016:0&gt; num=[1,2,3,4]\nirb(main):017:0&gt; alph=[\'a\',\'b\',\'c\',\'d\']\nirb(main):018:0&gt; l_enum=alph.to_enum\nirb(main):019:0&gt; s_enum=num.to_enum\nirb(main):020:0&gt; loop do\nirb(main):021:1* puts "#{s_enum.next} - #{l_enum.next}"\nirb(main):022:1&gt; end\n</code></pre>\n\n<p>Output:</p>\n\n<p>1 - a<br>\n2 - b<br>\n3 - c<br>\n4 - d</p>\n'}, {'answer_id': 11432676, 'author': 'Hossein', 'author_id': 1107992, 'author_profile': 'https://Stackoverflow.com/users/1107992', 'pm_score': 2, 'selected': False, 'text': '<pre><code>module Status\n  BAD  = 13\n  GOOD = 24\n\n  def self.to_str(status)\n    for sym in self.constants\n      if self.const_get(sym) == status\n        return sym.to_s\n      end\n    end\n  end\n\nend\n\n\nmystatus = Status::GOOD\n\nputs Status::to_str(mystatus)\n</code></pre>\n\n<p>Output:</p>\n\n<pre><code>GOOD\n</code></pre>\n'}, {'answer_id': 11455651, 'author': 'johnnypez', 'author_id': 366277, 'author_profile': 'https://Stackoverflow.com/users/366277', 'pm_score': 4, 'selected': False, 'text': "<p>This is my approach to enums in Ruby. I was going for short and sweet, not necessarily the the most C-like. Any thoughts?</p>\n<pre><code>module Kernel\n  def enum(values)\n    Module.new do |mod|\n      values.each_with_index{ |v,i| mod.const_set(v.to_s.capitalize, 2**i) }\n\n      def mod.inspect\n        &quot;#{self.name} {#{self.constants.join(', ')}}&quot;\n      end\n    end\n  end\nend\n\nStates = enum %w(Draft Published Trashed)\n=&gt; States {Draft, Published, Trashed} \n\nStates::Draft\n=&gt; 1\n\nStates::Published\n=&gt; 2\n\nStates::Trashed\n=&gt; 4\n\nStates::Draft | States::Trashed\n=&gt; 5\n</code></pre>\n"}, {'answer_id': 13764335, 'author': 'Oded Niv', 'author_id': 1056158, 'author_profile': 'https://Stackoverflow.com/users/1056158', 'pm_score': 4, 'selected': False, 'text': '<p>I know it\'s been a long time since the guy posted this question, but I had the same question and this post didn\'t give me the answer. I wanted an easy way to see what the number represents, easy comparison, and most of all ActiveRecord support for lookup using the column representing the enum.</p>\n\n<p>I didn\'t find anything, so I made an awesome implementation called <a href="https://github.com/toplex/enum" rel="nofollow noreferrer">yinum</a> which allowed everything I was looking for. Made ton of specs, so I\'m pretty sure it\'s safe.</p>\n\n<p>Some example features:</p>\n\n<pre><code>COLORS = Enum.new(:COLORS, :red =&gt; 1, :green =&gt; 2, :blue =&gt; 3)\n=&gt; COLORS(:red =&gt; 1, :green =&gt; 2, :blue =&gt; 3)\nCOLORS.red == 1 &amp;&amp; COLORS.red == :red\n=&gt; true\n\nclass Car &lt; ActiveRecord::Base    \n  attr_enum :color, :COLORS, :red =&gt; 1, :black =&gt; 2\nend\ncar = Car.new\ncar.color = :red / "red" / 1 / "1"\ncar.color\n=&gt; Car::COLORS.red\ncar.color.black?\n=&gt; false\nCar.red.to_sql\n=&gt; "SELECT `cars`.* FROM `cars` WHERE `cars`.`color` = 1"\nCar.last.red?\n=&gt; true\n</code></pre>\n'}, {'answer_id': 14087590, 'author': 'Daniel Doubleday', 'author_id': 1104754, 'author_profile': 'https://Stackoverflow.com/users/1104754', 'pm_score': 0, 'selected': False, 'text': '<p>Another way to mimic an enum with consistent equality handling (shamelessly adopted from Dave Thomas). Allows open enums (much like symbols) and closed (predefined) enums.</p>\n\n<pre><code>class Enum\n  def self.new(values = nil)\n    enum = Class.new do\n      unless values\n        def self.const_missing(name)\n          const_set(name, new(name))\n        end\n      end\n\n      def initialize(name)\n        @enum_name = name\n      end\n\n      def to_s\n        "#{self.class}::#@enum_name"\n      end\n    end\n\n    if values\n      enum.instance_eval do\n        values.each { |e| const_set(e, enum.new(e)) }\n      end\n    end\n\n    enum\n  end\nend\n\nGenre = Enum.new %w(Gothic Metal) # creates closed enum\nArchitecture = Enum.new           # creates open enum\n\nGenre::Gothic == Genre::Gothic        # =&gt; true\nGenre::Gothic != Architecture::Gothic # =&gt; true\n</code></pre>\n'}, {'answer_id': 16046129, 'author': 'jjk', 'author_id': 1965639, 'author_profile': 'https://Stackoverflow.com/users/1965639', 'pm_score': 2, 'selected': False, 'text': '<p>This seems a bit superfluous, but this is a methodology that I have used a few times, especially where I am integrating with xml or some such.</p>\n\n<pre><code>#model\nclass Profession\n  def self.pro_enum\n    {:BAKER =&gt; 0, \n     :MANAGER =&gt; 1, \n     :FIREMAN =&gt; 2, \n     :DEV =&gt; 3, \n     :VAL =&gt; ["BAKER", "MANAGER", "FIREMAN", "DEV"]\n    }\n  end\nend\n\nProfession.pro_enum[:DEV]      #=&gt;3\nProfession.pro_enum[:VAL][1]   #=&gt;MANAGER\n</code></pre>\n\n<p>This gives me the rigor of a c# enum and it is tied to the model.</p>\n'}, {'answer_id': 27349423, 'author': 'Vedant Agarwala', 'author_id': 1396264, 'author_profile': 'https://Stackoverflow.com/users/1396264', 'pm_score': 4, 'selected': False, 'text': '<p>If you are using Rails 4.2 or greater you can use Rails enums.</p>\n\n<p>Rails now has enums by default without the need for including any gems.</p>\n\n<p>This is very similar (and more with features) to Java, C++ enums.</p>\n\n<p>Quoted from <a href="http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html" rel="noreferrer">http://edgeapi.rubyonrails.org/classes/ActiveRecord/Enum.html</a> :</p>\n\n<pre><code>class Conversation &lt; ActiveRecord::Base\n  enum status: [ :active, :archived ]\nend\n\n# conversation.update! status: 0\nconversation.active!\nconversation.active? # =&gt; true\nconversation.status  # =&gt; "active"\n\n# conversation.update! status: 1\nconversation.archived!\nconversation.archived? # =&gt; true\nconversation.status    # =&gt; "archived"\n\n# conversation.update! status: 1\nconversation.status = "archived"\n\n# conversation.update! status: nil\nconversation.status = nil\nconversation.status.nil? # =&gt; true\nconversation.status      # =&gt; nil\n</code></pre>\n'}, {'answer_id': 27574382, 'author': 'Daniel Lubarov', 'author_id': 714009, 'author_profile': 'https://Stackoverflow.com/users/714009', 'pm_score': 3, 'selected': False, 'text': "<p>Perhaps the best lightweight approach would be</p>\n\n<pre><code>module MyConstants\n  ABC = Class.new\n  DEF = Class.new\n  GHI = Class.new\nend\n</code></pre>\n\n<p>This way values have associated names, as in Java/C#:</p>\n\n<pre><code>MyConstants::ABC\n=&gt; MyConstants::ABC\n</code></pre>\n\n<p>To get all values, you can do</p>\n\n<pre><code>MyConstants.constants\n=&gt; [:ABC, :DEF, :GHI] \n</code></pre>\n\n<p>If you want an enum's ordinal value, you can do</p>\n\n<pre><code>MyConstants.constants.index :GHI\n=&gt; 2\n</code></pre>\n"}, {'answer_id': 32149803, 'author': 'dark_src', 'author_id': 371572, 'author_profile': 'https://Stackoverflow.com/users/371572', 'pm_score': 1, 'selected': False, 'text': '<p>Sometimes all I need is to be able to fetch enum\'s value and identify its name similar to java world.</p>\n\n<pre><code>module Enum\n     def get_value(str)\n       const_get(str)\n     end\n     def get_name(sym)\n       sym.to_s.upcase\n     end\n end\n\n class Fruits\n   include Enum\n   APPLE = "Delicious"\n   MANGO = "Sweet"\n end\n\n Fruits.get_value(\'APPLE\') #\'Delicious\'\n Fruits.get_value(\'MANGO\') # \'Sweet\'\n\n Fruits.get_name(:apple) # \'APPLE\'\n Fruits.get_name(:mango) # \'MANGO\'\n</code></pre>\n\n<p>This to me serves the purpose of enum and keeps it very extensible too. You can add more methods to the Enum class and viola get them for free in all the defined enums. for example. get_all_names and stuff like that.</p>\n'}, {'answer_id': 34498312, 'author': 'ka8725', 'author_id': 1178074, 'author_profile': 'https://Stackoverflow.com/users/1178074', 'pm_score': 2, 'selected': False, 'text': '<p>Recently we released a <a href="https://github.com/mezuka/enum" rel="nofollow">gem</a> that implements <strong>Enums in Ruby</strong>. In my <a href="http://railsguides.net/safe-enums-in-ruby/" rel="nofollow">post</a> you will find the answers on your questions. Also I described there why our implementation is better than existing ones (actually there are many implementations of this feature in Ruby yet as gems). </p>\n'}, {'answer_id': 45097718, 'author': 'Roger', 'author_id': 549010, 'author_profile': 'https://Stackoverflow.com/users/549010', 'pm_score': 3, 'selected': False, 'text': '<p>Another solution is using OpenStruct. Its pretty straight forward and clean.</p>\n\n<p><a href="https://ruby-doc.org/stdlib-2.3.1/libdoc/ostruct/rdoc/OpenStruct.html" rel="noreferrer">https://ruby-doc.org/stdlib-2.3.1/libdoc/ostruct/rdoc/OpenStruct.html</a></p>\n\n<p>Example:</p>\n\n<pre><code># bar.rb\nrequire \'ostruct\' # not needed when using Rails\n\n# by patching Array you have a simple way of creating a ENUM-style\nclass Array\n   def to_enum(base=0)\n      OpenStruct.new(map.with_index(base).to_h)\n   end\nend\n\nclass Bar\n\n    MY_ENUM = OpenStruct.new(ONE: 1, TWO: 2, THREE: 3)\n    MY_ENUM2 = %w[ONE TWO THREE].to_enum\n\n    def use_enum (value)\n        case value\n        when MY_ENUM.ONE\n            puts "Hello, this is ENUM 1"\n        when MY_ENUM.TWO\n            puts "Hello, this is ENUM 2"\n        when MY_ENUM.THREE\n            puts "Hello, this is ENUM 3"\n        else\n            puts "#{value} not found in ENUM"\n        end\n    end\n\nend\n\n# usage\nfoo = Bar.new    \nfoo.use_enum 1\nfoo.use_enum 2\nfoo.use_enum 9\n\n\n# put this code in a file \'bar.rb\', start IRB and type: load \'bar.rb\'\n</code></pre>\n'}, {'answer_id': 48199917, 'author': 'horun', 'author_id': 3940165, 'author_profile': 'https://Stackoverflow.com/users/3940165', 'pm_score': 1, 'selected': False, 'text': '<p>Try the inum.\n<a href="https://github.com/alfa-jpn/inum" rel="nofollow noreferrer">https://github.com/alfa-jpn/inum</a></p>\n\n<pre class="lang-js prettyprint-override"><code>class Color &lt; Inum::Base\n  define :RED\n  define :GREEN\n  define :BLUE\nend\n</code></pre>\n\n<pre class="lang-js prettyprint-override"><code>Color::RED \nColor.parse(\'blue\') # =&gt; Color::BLUE\nColor.parse(2)      # =&gt; Color::GREEN\n</code></pre>\n\n<p>see more <a href="https://github.com/alfa-jpn/inum#usage" rel="nofollow noreferrer">https://github.com/alfa-jpn/inum#usage</a></p>\n'}]
['https://Stackoverflow.com/questions/75759', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4110/']