Add alternative letter casings for Enum
names
#14226
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I need these in enums all the time. A lot of times, enum values are serialized in other systems (databases, third-party services, etc) differently, so I usually implement these methods myself in my apps. I wasn't sure how many other people were experiencing this, but then I saw this thread on the forum, so I'm clearly not alone in this.
In hindsight,
snakecase_name
should probably beunderscore_name
to matchString#underscore
. We don't seem to have any precedent forkebabcase
in the stdlib, but it's pretty common to serialize low-cardinality multi-word string values this way.This isn't complete yet, there are still a couple things that should be done, but I wanted to get something started since I'd already written the code for the forum post.
Enum#to_json
to usesnakecase_name
(orunderscore_name
, whatever we call it) rather than its current bespoke implementationmember_name
because I'd forgotten about thisFlags
support