Skip to content

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


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