lib/enumerated_constants.rb in enumerated_constants-0.2.0 vs lib/enumerated_constants.rb in enumerated_constants-0.3.0

- old
+ new

@@ -1,7 +1,9 @@ require 'forwardable' +# Mix-in that allows you to treat a module of related constants like +# a good ol' fashioned enum. module EnumeratedConstants extend Forwardable def all @all ||= constants.map(&method(:const_get)).delete_if do |constant| @@ -13,15 +15,15 @@ # Return all but the constant name you pass # @param name [Symbol,String] The name of the constant you don't want # @return [Array] @all except the value of that constant def except(*names) - const_names = names = names.map(&:upcase).map(&:to_sym) values = names.map do |name| begin const_get(name) rescue NameError + raise ArgumentError, "Constant #{name} does not exist" end end.compact all - values end end