Replace `class_eval` with `define_method` for enum

https://github.com/rails/rails/commit/db41eb8a6ea88b854bf5cd11070ea4245e1639c5#commitcomment-4502683
Merge pull request #12754 from ck3g/replace-class-evals-with-define-method-for-enum

Replace `class_eval` with `define_method` for enum