Module: EnumeratedConstants

Extended by:
Forwardable
Defined in:
lib/enumerated_constants.rb

Instance Method Summary collapse

Instance Method Details

#allObject



6
7
8
9
10
# File 'lib/enumerated_constants.rb', line 6

def all
  @all ||= constants.map(&method(:const_get)).delete_if do |constant|
    constant.is_a?(Array)
  end.freeze
end

#except(*names) ⇒ Array

Return all but the constant name you pass

Parameters:

  • name (Symbol, String)

    The name of the constant you don’t want

Returns:

  • (Array)

    @all except the value of that constant



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/enumerated_constants.rb', line 17

def except(*names)
  const_names =
  names = names.map(&:upcase).map(&:to_sym)
  values = names.map do |name|
    begin
      const_get(name)
    rescue NameError
    end
  end.compact
  all - values
end