Updates to Avram Enums : ==, ===, enum constants#566
Updates to Avram Enums : ==, ===, enum constants#566jwoertink merged 4 commits intoluckyframework:masterfrom
Conversation
jwoertink
left a comment
There was a problem hiding this comment.
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. |
| self.enum == other.enum | ||
| end | ||
|
|
||
| delegate :===, to_s, to_i, to: @enum |
There was a problem hiding this comment.
Do we still need to delegate === here?
There was a problem hiding this comment.
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. |
jwoertink
left a comment
There was a problem hiding this comment.
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 }} |
This implements
==and===methods on avram_enum generated structures, and also implements explicit constant accessors to decrease the difference between Enum and avram_enum.