-
Notifications
You must be signed in to change notification settings - Fork 64
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
Updates to Avram Enums : ==, ===, enum constants #566
Conversation
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.
I love this. Question.... Should we also add in the threequals ===
? I think case
uses that, right?
Also provides named constants which reflect the underlying enum values
Using a An instance of a |
@akadusei By converting the enum wrapper to a struct I was indeed able to remove the explicit definition of the #== operator. Honestly I don't know all the implications of this kind of change, though from all my reading a struct is better than a class wherever you can. I don't know what the knock-on effects of this will be in developer applications. I added it here a a separate commit which can be rebased out if undesired. |
def ==(other : {{ enum_name }}) : Bool | ||
self.enum == other.enum | ||
end | ||
|
||
delegate :===, to_s, to_i, to: @enum |
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.
Do we still need to delegate ===
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.
Yep, the case equality tests fail without it.
Looks good. Apps should not have any issues, unless they are reopening the class (now struct) for some reason. |
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.
I haven't used the enum yet, but I think this looks good. Only way to really know is get it in the hands of people!
end | ||
|
||
class {{ enum_name }} | ||
struct {{ enum_name }} |
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.
nice! 👍
This implements
==
and===
methods on avram_enum generated structures, and also implements explicit constant accessors to decrease the difference between Enum and avram_enum.