Skip to content

Commit

Permalink
Follow Rails project conventions for class_eval
Browse files Browse the repository at this point in the history
Setting the line number properly helps with stack walkbacks and debugging.
  • Loading branch information
flavorjones committed Sep 4, 2024
1 parent 3a7a17f commit 59e79da
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/enum/enum.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ def enum(columns)
columns.each do |column, values|
values = values.zip(values.map(&:to_s)).to_h if values.is_a?(Array)
values.each do |method, value|
method_definitions << "def #{method}?; #{column} == #{value.inspect}; end"
class_eval <<~METHOD, __FILE__, __LINE__ + 1
# frozen_string_literal: true
def #{method}?
#{column} == #{value.inspect}
end
METHOD
end
end
class_eval(method_definitions.uniq.join(";"))
end

def insert(record)
Expand Down

0 comments on commit 59e79da

Please sign in to comment.