According to the documentation for getoptlong.rb, the GetoptLong.new method requires an array of arrays to be passed:
# The options to support are passed to new() as an array of arrays.
# Each sub-array contains any number of String option names which carry
# the same meaning, and one of the following flags:
However, this code fails:
require 'getoptlong'
options = GetoptLong.new(
[
['-a', GetoptLong::NO_ARGUMENT],
['-b', GetoptLong::NO_ARGUMENT],
]
)
This works:
require 'getoptlong'
options = GetoptLong.new(
['-a', GetoptLong::NO_ARGUMENT],
['-b', GetoptLong::NO_ARGUMENT]
)
Either the documentation could be fixed, or the call could accept an array of arrays. Personally, I prefer the latter,
since it allows something like this:
options = GetoptLong.new(
[
['-a', GetoptLong::NO_ARGUMENT],
['-b', GetoptLong::NO_ARGUMENT],
# ['--debug', GetoptLong::NO_ARGUMENT],
]
)
which the other form does not allow without removing the comma from the -b line too.
I made a patch againt 1.8.5 that lets set_options (and by extension initialize) accept both forms.
What do you people think? |