-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Flags enums: prevent All
and None
keywords
#1251
Comments
Probably. I don't know if there's a use case where you'd want to overwrite those, and in any case it would yield unexpected results. Thanks for noticing this! |
Borrowing decioferreira's example: @[Flags(all: :All, none: :Empty)]
enum IOMode
In # 1
Out # 2
end
puts IOMode::Empty.value #=> 0 because the "none" name was set to :Empty
puts IOMode::All.value #=> 3 because the "all" name was set to :All
puts IOMode::None.value # error: no such constant For a default setting, though, it makes sense to provide at least a warning if things like |
I think that having |
|
I see the argument OTOH it seems like a handy tool too. Maybe we can come up with some more explicit way of defining it, like |
I agree that it would be nice for an opt-out for All/None. And if opted out let the user define/use them (just by plain values as other constants). All/None have special meaning in Enum#to_s, Enum#each, etc. I wouldn't allow All/None to lose their special semantic. |
Should the compiler prevent the definition of
All
andNone
keywords on flag enums?The text was updated successfully, but these errors were encountered: