Sha256: ff03d36504f492166b362427b18bec8ac2bba742e0eb378332b7d83fb96b0292

Contents?: true

Size: 587 Bytes

Versions: 6

Compression:

Stored size: 587 Bytes

Contents

require 'forwardable'

module Renum
  class EnumeratedValue
    
    class << self
      include Enumerable
      extend Forwardable
      
      def_delegators :values, :each, :[]
      
      def values
        @values ||= []
      end
      
    end
    
    include Comparable
    attr_reader :name
    attr_reader :index
    
    def initialize name
      @name = name.to_s
      @index = self.class.values.size
      self.class.values << self
    end
    
    def to_s
      "#{self.class}::#{name}"
    end
    
    def <=> other
      index <=> other.index
    end
    
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
duelinmarkers-renum-1.0.2 lib/renum/enumerated_value.rb
duelinmarkers-renum-1.1.0 lib/renum/enumerated_value.rb
duelinmarkers-renum-1.2.0 lib/renum/enumerated_value.rb
rickenharp-renum-1.0.1 lib/renum/enumerated_value.rb
renum-1.0.1 lib/renum/enumerated_value.rb
renum-1.0.2 lib/renum/enumerated_value.rb