Skip to content
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

overwrite to_s and to_i for Enums #474

Merged
merged 6 commits into from Oct 5, 2020
Merged

Conversation

confact
Copy link
Contributor

@confact confact commented Oct 3, 2020

making it possible to get int and the string directly, good for showing the enum on pages and such.

Not it will return class instance on to_s and not work at all on to_i

now it will return say Ongoing on to_s and 0 on to_i

not sure if maybe this will work instead:

delegate :to_s, :to_i, to: @enum

I feel it is a personal taste that feels best. I can change to that if you want.

making it possible to get int and the string directly, good for showing the enum on pages and such.

Not it will return class instance on `to_s` and not work at all on `to_i`
@confact confact changed the title overwrite to_s and to_i overwrite to_s and to_i for Enums Oct 5, 2020
Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do use some delegation in Lucky as well https://github.com/luckyframework/lucky/search?q=delegate so I'd be ok with that. Also, right below this is the forward_missing_to @enum. Does that not already forward to_s and to_i? Or is it because all objects kind of respond to to_s that it's not really forwarded?

@confact
Copy link
Contributor Author

confact commented Oct 5, 2020

@jwoertink as to_s and to_i is not missed as it exists in more or less every object it will not forward those.

I moved it to delegate now.

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet. Looks good to me! Thanks 😄

@jwoertink jwoertink merged commit b072877 into luckyframework:master Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants