-
-
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
Add include and extend to Enum #8946
Comments
Already addressed by Ary in #8943 ❤️ |
Related it's also not possible to use enum Test
One
Two
class Bar
end
end
pp Test::Bar.new # => Error: unexpected token: class Maybe there's a reason for this but seems a bit unexpected. |
The reason is that all constants inside the enum are the enum members. If we allow classes or modules then that's not true anymore. But maybe it's a restriction we can remove. |
If we consider allowing to use types in enum namespace, we could also consider arbitrary, non-member constants. This would allow doing this: #10281 (comment) (see OP for context). |
There is a possibly unintended alternative to enum A
X
end
module B
def foo
end
end
alias AClass = A.class
class AClass
include B # okay
end
A.foo # okay The only difference is it would call a different macro hook. (Note that extending a module inside |
Why was #8943 not merged? |
I would like the posibility to use include and extend on Enum.
Now they are added to Enum.class but not to the actual Enum.
Say we do:
And extend or include in an enum it will be only in Enum. And using include and extend won't work inside
enum Status
So this won't work, but would probably solve the issue i am telling in detail below:
Why I want this?
Most ORM adds module or methods to parse, get data from database and to database to a type, so-called type extensions. Enum is handling include and extend differently making this not work. And can therefore not use Enums as a type for columns without some type of wrapper class around the enum to cast it correctly and so on.
The text was updated successfully, but these errors were encountered: