diff --git a/lib/enum/enum.rb b/lib/enum/enum.rb index fef6665..6f07ebc 100644 --- a/lib/enum/enum.rb +++ b/lib/enum/enum.rb @@ -15,14 +15,14 @@ def enum_accessor(*field_names) end def enum(columns) + method_definitions = [] columns.each do |column, values| values = values.zip(values.map(&:to_s)).to_h if values.is_a?(Array) values.each do |method, value| - define_method("#{method}?") do - send(column) == value - end + method_definitions << "def #{method}?; #{column} == '#{value}'; end" end end + class_eval(method_definitions.uniq.join(";")) end def insert(record)