Module: Enum::Predicates
- Defined in:
- lib/enum/predicates.rb
Instance Method Summary collapse
-
#enumerize(field, enum) ⇒ Object
TODO : check if still working with hashes instead of strings.
Instance Method Details
#enumerize(field, enum) ⇒ Object
TODO : check if still working with hashes instead of strings
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/enum/predicates.rb', line 4 def enumerize(field, enum) define_method("#{field}_is?") do |other| if (field_value = public_send(field)) && other enum.enum(field_value) == enum.enum(other) else false end end define_method("#{field}_any?") do |*others| others.each { |other| enum.enum(other) } # make sure that all others values are valid enums others.any? { |other| public_send("#{field}_is?", other) } end end |