-
-
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
Can't cast symbol to enum in initialize() arg list #6279
Comments
Right, the rule is: if there's an enum type restriction, you can pass a symbol. Going from there to "if there's an argument with a default value, and that argument gets assigned to an instance variable, and that instance variable has an enum type, then..." is a bit of a stretch, and it's way harder to implement and understand. Please let's not go this route. It's simpler to add the type restrictions. It takes less time than writing a whole github issue ;-) |
I see. I thought a default value also imposed a type restriction on the argument. |
Not necessarily. A default value's type could be a subset of the type. For example the default value could be |
Makes sense. |
By the way, you can also write: def initialize(number : MyEnum = :one)
end which is more or less the same as typing: def initialize(number = MyEnum::One)
end (if the problem you are having is having to type a lot) |
I wanted to replace the fully-qualified enum references in my code with symbols following #6074 being released, but I can't do that everywhere it seems.
Can this be made to work?
The text was updated successfully, but these errors were encountered: