Sha256: cdfa63a02b0f999d6ef7ef193dcd2df5908462dc2ad28f8c3f8c937e635f410a

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

#--
# EnumeratedType
#
# Copyright (c) 2005 Jamis Buck
#
# Ruby License
#
# This module is free software. You may use, modify, and/or redistribute this
# software under the same terms as Ruby.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
#
# ==========================================================================
# Revision History ::
# --------------------------------------------------------------------------
#  05.09.13  trans   * Added or-able option which will enum by powers of 2.
#  05.08.07  trans   * Ported to Mega Modules
# ==========================================================================
#++

#:title: EnumeratedType
#
# EnumeratedType lets you create enumerated types like this:
#
#   class OutputType < EnumeratedType
#     AUTODETECT
#     UNKNOWN
#     NOSOUND
#     WAVWRITER
#     DSOUND
#     WINMM
#     ASIO
#     OSS
#     ALSA
#     ESD
#     SOUNDMANAGER
#     COREAUDIO
#     XBOX
#     PS2
#     GC
#     XBOX360
#     PSP
#   end
#
# If you want to start with a different integer than 0, you can just do:
#
#   class OutputType < EnumeratedType
#     start 15
#     AUTODETECT
#     ...
#   end
#
# You can also use start anywhere in the list, to have subsequent constants
# enumerated starting with the given value.
#
# == Author(s)
#
# * James Buck
#

class EnumeratedType
  class << self
    def start(n, orable=false)
      @next_value = n
      @orable = orable
    end

    def const_missing(sym)
      @next_value ||= 0
      const_set(sym, @next_value)
      if @orable
        @next_value *= 2
      else
        @next_value += 1
      end
    end
  end
end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#

# TODO

=begin testing

  require 'test/unit'

  class TC_EnumeratedType < Test::Unit::TestCase

    def test_01
    end

  end

=end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
facets-0.9.0 lib/mega/enumtype.rb