Skip to content

Modernize #set_options.#20

Open
RuhmUndAnsehen wants to merge 2 commits intoruby:masterfrom
RuhmUndAnsehen:modernize_set_options
Open

Modernize #set_options.#20
RuhmUndAnsehen wants to merge 2 commits intoruby:masterfrom
RuhmUndAnsehen:modernize_set_options

Conversation

@RuhmUndAnsehen
Copy link
Copy Markdown
Contributor

@RuhmUndAnsehen RuhmUndAnsehen commented Nov 2, 2025

GetoptLong#set_options is very long and I also found it hard to read, so I took the liberty of modernizing the code.

API changes

First things first, the second commit in the PR contains a minor API change: Option lists now may be any iterable, not just arrays. This required changing the error message and the respective test case.

Description

Previously, sanitation checks and modifications of instance variables happened interchangeably. This required a cleanup step if errors occured.
Now, as a first step, the options list gets partitioned in flags and option names. This allowed me to put the validations first and process the entries later, and to drop the cleanup section. Partitioning also superseded the need to check if canonical_name was nil at the end.

@RuhmUndAnsehen RuhmUndAnsehen changed the title Modernize set options Modernize #set_options. Nov 2, 2025
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