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

Use double-splat for Ruby 3.0 compatibility #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

qnighy
Copy link

@qnighy qnighy commented Jan 6, 2021

Ruby 3.0 separates keyword arguments from positional arguments. https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

This PR makes simple_enum compatible with the new behavior. As ** isn't supported in Ruby 1.9, this PR falls back to the old source code without ** when a syntax error occurs.

@guillaumebesse
Copy link

Hi @qnighy thank you for your PR.
Just a question: to avoid code duplication why you didn't use RUBY_VERSION, something like

if RUBY_VERSION < "1.9"
   I18n.translate(defaults.shift, options)
else   
    I18n.translate(defaults.shift, **options)
end

@qnighy
Copy link
Author

qnighy commented Jan 14, 2022

Because in the old Ruby, SyntaxError would be raised before executing the whole if expression.

@softbrada
Copy link

any updates on this PR? I really need these changes.

@lwe
Copy link
Owner

lwe commented Aug 15, 2022

@guillaumebesse any chance you could fix up the PR and merge it?

require 'simple_enum/translation'
begin
require 'simple_enum/translation'
rescue SyntaxError
Copy link

@softbrada softbrada Aug 17, 2022

Choose a reason for hiding this comment

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

i am not a maintainer, or contributor to this project, probably should also be ArgumentError here. On Ruby 2.6 i get ArgumentError rather than SyntaxError. Just sharing my thoughts

@@ -15,7 +15,7 @@ def human_enum_name(enum, key, options = {})
defaults << key.to_s.humanize

options.reverse_merge! count: 1, default: defaults
I18n.translate(defaults.shift, options)
I18n.translate(defaults.shift, **options)
Copy link

@softbrada softbrada Aug 17, 2022

Choose a reason for hiding this comment

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

i am not a maintainer, or contributor to this project, but seems brittle to me to have this whole file duplicated to fix a single line.

We could rescue here the exception so we avoid duplicating unnecessary code. Just my thoughts

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.

4 participants