From 59e79da226e960590ff41ef1f1dd6dfeb934deb6 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 4 Sep 2024 08:13:21 -0400 Subject: [PATCH] Follow Rails project conventions for class_eval Setting the line number properly helps with stack walkbacks and debugging. --- lib/enum/enum.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/enum/enum.rb b/lib/enum/enum.rb index e022305..fb6e0a4 100644 --- a/lib/enum/enum.rb +++ b/lib/enum/enum.rb @@ -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)