Bugs: Browse | Submit New | Admin

[#8384] Discrepancy between GetoptLong.new and documentation

Date:
2007-02-02 09:06
Priority:
3
Submitted By:
Roel Harbers (rharbers)
Assigned To:
Nobody (None)
Category:
Developer Tools/Libs
State:
Open
Platform:
 
Summary:
Discrepancy between GetoptLong.new and documentation

Detailed description
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?

Add A Comment: Notepad

Please login


Followup

Message
Date: 2007-03-21 18:01
Sender: Roel Harbers

Anyone? class? Bueller?

Attached Files:

Name Description Download
getoptlong.rb.diff diff for allowing an array of arrays in GetoptLong.new Download
getoptlong.rb.diff even shorter diff for allowing an array of arrays in GetoptLong.new Download

Changes:

Field Old Value Date By
assigned_tozenspider2009-02-17 23:12zenspider
assigned_tonone2007-06-12 01:20zenspider
category_idMisc / Other Standard Library2007-05-29 20:55zenspider
File Added1207: getoptlong.rb.diff2007-02-02 09:54rharbers
File Added1206: getoptlong.rb.diff2007-02-02 09:06rharbers