Skip to content

Allow required options to be initialised with string keys - #929

Open
JoelTowell wants to merge 3 commits into
rails:mainfrom
JoelTowell:fix-non-indifferent-access-required-options
Open

JoelTowell wants to merge 3 commits into
rails:mainfrom
JoelTowell:fix-non-indifferent-access-required-options

Conversation

@JoelTowell

@JoelTowell JoelTowell commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

🌈

Problem

Thor supports passing initialised options with either symbol or string keys.

MyCounter.new [1, 2], third: 4
MyCounter.new [1, 2], "third" => 4

However, when the option is required, the string-key form raises Thor::RequiredArgumentMissingError.

This also affects invoke when a required option is declared with a string key and passed with a symbol key, as in #614. I checked that reproduction against this branch and it now passes.

Reproduction

The first commit on this branch adds a failing example for this. It can be checked out independently to see the failure.

Solution

Update the required option check in Thor::Options to use a lookup with indifferent access when removing options from @non_assigned_required.

This branch has not been deployed

No deployments
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.

1 participant