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

Make keyword arguments delegation compatible with ruby v3 #70

Merged
merged 2 commits into from
Nov 24, 2022

Conversation

Mat-Co
Copy link
Contributor

@Mat-Co Mat-Co commented Nov 23, 2022

How keyword arguments are passed has changed with ruby v3, they now have to be explicitly delegated, see https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

This patch add compatibility with Ruby v3 (which is embedded in recent versions of Chef), but also keep this cookbook functional with lower versions.

@@ -44,10 +44,11 @@ def initialize(name, &block)
# read all available primitives and make them available with a method
# using their name. It allows to call `check_file '/tmp/titi'` to
# instantiate the CheckFile primitive
delegated_args = RUBY_VERSION < '3' ? '*args, &block' : '*args, **kwargs, &block'
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and below please use RUBY_VERSION.to_i < 3; your code works ... until we get to ruby 10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, will do! I hope we will able to drop ruby 2.7 support and remove this fix before Ruby v10, but yes :)

@Annih Annih merged commit 394814f into master Nov 24, 2022
@Annih Annih deleted the kwargs_deleg_ruby_v2_v3_compat branch November 24, 2022 11:34
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.

2 participants