Sha256: 305a867ad78a4ed8d111cbbbb69ebfdef357b0cc65447f089ee3ecdcec63ec86

Contents?: true

Size: 588 Bytes

Versions: 2

Compression:

Stored size: 588 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
    
    def initialize name
      @name = name.to_s
      self.class.values << self
    end
    
    def to_s
      "#{self.class}::#{name}"
    end
    
    def index
      self.class.values.index self
    end
    
    def <=> other
      index <=> other.index
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
renum-0.1.0 lib/renum/enumerated_value.rb
renum-1.0.0 lib/renum/enumerated_value.rb