Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum: better styling #361

Open
pirj opened this issue Oct 30, 2024 · 3 comments
Open

Enum: better styling #361

pirj opened this issue Oct 30, 2024 · 3 comments
Assignees

Comments

@pirj
Copy link
Member

pirj commented Oct 30, 2024

We suggest the kwargs-style enum definition:

  enum type: {
    credit: 0,
    debit: 1
  }

This is problematic in two ways.

  1. Passing options like prefix/suffix/scopes/default is complicated (needs to be prefixed with an underscore) and is not documented
  2. Results in weird unrelated errors (mentions the very first defined enum instead of the one that has options)

Ok to change this to use positional args for name and values?

  enum :type, {
    credit: 0,
    debit: 1
  }

With options:

  enum :type, {
    credit: 0,
    debit: 1
  }, suffix: true
@pirj pirj self-assigned this Oct 30, 2024
@Earlopain
Copy link

Not sure if you're aware, but there's a cop for this now: rubocop/rubocop-rails#1336
It is only is for Ruby >= 3.0 because on 2.7 it can cause keyword argument warnings (rubocop/rubocop-rails#1363). The new syntax itself was introduced with Rails 7.0

@pirj
Copy link
Member Author

pirj commented Nov 19, 2024

@koic @andyw8 wdyt?

@pirj
Copy link
Member Author

pirj commented Nov 19, 2024

Off-topic: Rails 6.1 is EOL a month ago, is it a good idea to scrub the guide from legacy content, and leave a note that pre-7 guidelines are only kept in the GitHub repo (in a branch).?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants