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 call to shell_out compatible with Ruby 3 #257

Merged
merged 1 commit into from Mar 31, 2022

Conversation

foygl
Copy link
Contributor

@foygl foygl commented Mar 25, 2022

Description

In previous versions of Ruby, calling shell_out("cmd", { blah : "blah" }) would be interpreted correctly here as args = "cmd" and options = { blah : "blah" }.

However because this can be ambiguous to interpret, Ruby would give the warning:

warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call

As of Ruby 3, shell_out("cmd", { blah : "blah" }) will be interpreted as args = ["cmd", { blah : "blah" }] and options = {}.

This can be fixed by passing in the options parameter with a double splat (**) in front of it to explicitly convert the hash into a keyword argument.

Issues Resolved

No open issues.

Check List

In previous versions of Ruby, calling `shell_out("cmd", { blah : "blah" })` would be interpreted correctly [here](https://github.com/chef/mixlib-shellout/blob/e2ec87f6f5933e5e5bc75a9fe08a8c8c73e55b72/lib/mixlib/shellout/helper.rb#L38) as `args = "cmd"` and `options = { blah : "blah" }`.

However because this can be ambiguous to interpret, Ruby would give the warning:
```
warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call
```

As of Ruby 3, `shell_out("cmd", { blah : "blah" })` will be interpreted as `args = ["cmd", { blah : "blah" }]` and `options = {}`.

This can be fixed by passing in the `options` parameter with a double splat (**) in front of it to explicitly convert the hash into a keyword argument.

Signed-off-by: William Starling <william@bugsnag.com>
@lamont-granquist lamont-granquist merged commit fe98b24 into chef-cookbooks:main Mar 31, 2022
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