Skip to content

Commit

Permalink
refactor: use class_eval
Browse files Browse the repository at this point in the history
  • Loading branch information
hatsu38 committed Aug 31, 2024
1 parent 22147a3 commit 8da980b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/enum/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8da980b

Please sign in to comment.