# This module should be used for situations where enumerating over constant values is desired.
# This facilitates keeping the code DRY by keeping the constant values defined in one place, and
# still having the ability to enumerate over them wherever they are needed.
# Example use cases:
# * defining constants for possible field values in an AR object and including this module to
# provide access to the values in a 'validates_inclusion_of' validation
# * defining constants for select box values in a view and including this module to allow them to be
# enumerated over in the select tag
class << mod
@enumerable_consts = consts unless consts.empty?
# Yields each constant value to &block. By default, all constants defined by the
# including class are yielded. If specific constants are to be yielded, call
# EnumerableConstants#enumerable(*consts) before calling this method.
consts = @enumerable_consts || self.constants.grep(/[^a-z][A-Z_]+/)
consts.each do |const|
# #each_constant is provided as syntactic sugar for situations where it may be more appropriate than #each
alias_method :each_constant, :each