-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add "Positional arguments" subsection #356
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,6 +422,8 @@ end | |
|
||
=== Enums [[enums]] | ||
|
||
=== Hash syntax [[hash-syntax]] | ||
|
||
Prefer using the hash syntax for `enum`. Array makes the database values implicit | ||
& any insertion/removal/rearrangement of values in the middle will most probably | ||
lead to broken code. | ||
|
@@ -440,6 +442,22 @@ class Transaction < ApplicationRecord | |
end | ||
---- | ||
|
||
=== Positional arguments [[positional-arguments]] | ||
|
||
Prefer using positional arguments instead of keyword arguments when defining enums. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I’m on the fence if this should be in the guide. I can also see potential mistakes like But how does that stylistically differ for the rest of us? Why do people need to care? If it’s older Rails - use any of the teo. If it’s new, only the positional would work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right - since deprecation notice captures the old syntax, seems like we don't need to have a dedicated cop for this at all, I'll close both PRs 😬 thanks for the feedback! |
||
Defining enums with keyword arguments is deprecated and will be removed in Rails 7.3. | ||
|
||
[source,ruby] | ||
---- | ||
class Transaction < ApplicationRecord | ||
# bad | ||
enum status: { active: 0, archived: 1 }, _prefix: true | ||
|
||
# good | ||
enum :status, { active: 0, archived: 1 }, prefix: true | ||
end | ||
---- | ||
|
||
=== Macro Style Methods [[macro-style-methods]] | ||
|
||
Group macro-style methods (`has_many`, `validates`, etc) in the beginning of the class definition. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a sub-section, so four ====