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

Enhance to support 'Set' object as an enum #76

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kwatch
Copy link

@kwatch kwatch commented Oct 3, 2024

OptionParser supports Array and Hash object as an enum of option value.
But Set object is not supported.
For example:

require 'optparse'

parser = OptionParser.new
parser.on("--lang1=<lang>", ["en", "fr", "it"])   # option value will be checked by enum values
parser.on("--lang2=<lang>", Set.new(["en", "fr", "it"]))   # will not be checked when Set object

opts = {}
parser.parse(["--lang2", "ja"], into: opts)   # !!! not raise error !!!
parser.parse(["--lang1", "ja"], into: opts)   # raises error expectedly
p opts

Since Ruby 3.2, Set class is a built-in class.
I think that it is very natural for OptionParser to support Set object.

By the way, I can't find a test script to test OptionParser#make_switch() method.
Therefore this pull request doesn't contain any test case.

@kwatch
Copy link
Author

kwatch commented Oct 3, 2024

By the way, I can't find a test script to test OptionParser#make_switch() method.
Therefore this pull request doesn't contain any test case.

Added new test script test/optparse/test_switch.rb.
If you find something to improve in it, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant