-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Rename the enum_prefix and enum_suffix options to _prefix and _suffix #20999
Conversation
This makes it more clear that they are reserved keywords and also it seems less redundant as the line already starts with the call to the `enum` method.
Rename the enum_prefix and enum_suffix options to _prefix and _suffix
Sweet, thanks! Have a nice day too 😄 |
Thanks! :-) |
# Note that <tt>:enum_prefix</tt>/<tt>:enum_suffix</tt> are reserved keywords | ||
# and can not be used as an enum name. | ||
# Note that <tt>:_prefix</tt>/<tt>:_suffix</tt> are reserved keywords and can | ||
# not be used as enum names. |
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.
We can probably ✂️ now? Seems unlikely that people would try to use _
names, so while it's technically still true, it is just adding noise to me. What do you think?
Would trade that with an example of the feature. It doesn't really explain what the feature does, if you didn't know about the history here it seems unlikely that you would understand what it does/why you would need it from reading the docs here
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.
to define multiple enums with same values
would be nice if the examples actually show that use case 😄
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.
Yes, you're totally right! 👍 Will send a patch then!
The note regarding the `_prefix` and `_suffix` options is no longer useful since they were renamed specifically for this purpose. Also the given example doesn't show what these options enable and in which case they are really useful (when there are conflicting values for instance). Refs #20999. [Godfrey Chan & Robin Dupret]
… skip] `:enum_prefix` and `:enum_suffix` was changed to `:_prefix` and `:_suffix` in rails#20999.
Unlike other features built on Attribute API, reserved options for `enum` has leading `_`. * `_prefix`/`_suffix`: rails#19813, rails#20999 * `_scopes`: rails#34605 * `_default`: rails#39820 That is due to `enum` takes one hash argument only, which contains both enum definitions and reserved options. I propose new syntax for `enum` to avoid leading `_` from reserved options, by allowing `enum(attr_name, ..., **options)` more Attribute API like syntax. Before: ```ruby class Book < ActiveRecord::Base enum status: [ :proposed, :written ], _prefix: true, _scopes: false enum cover: [ :hard, :soft ], _suffix: true, _default: :hard end ``` After: ```ruby class Book < ActiveRecord::Base enum :status, [ :proposed, :written ], prefix: true, scopes: false enum :cover, [ :hard, :soft ], suffix: true, default: :hard end ```
Hello,
This pull request renames the
enum_{prefix_suffix}
options to_{prefix_suffix}
in order to make it more clear that they are reserved keywords and also it seems less redundant as the line already starts with the call to theenum
method.Cross-refs #19813 (comment).
Have a nice day.