lib/getopt/long.rb in getopt-1.4.3 vs lib/getopt/long.rb in getopt-1.4.4

- old
+ new

@@ -1,5 +1,7 @@ +require_relative 'version' + # The Getopt module serves as a namespace only module Getopt REQUIRED = 0 # Argument is required if switch is provided. BOOLEAN = 1 # Value of argument is true if provided, false otherwise. @@ -10,17 +12,15 @@ # INTEGER = 5 # Argument automatically converted to integer if provided. # FLOAT = 6 # Argument automatically converted to float if provided. # The Getopt::Long class encapsulates longhanded parameter parsing options class Long + include Getopt::Version # Error raised if an illegal option or argument is passed class Error < StandardError; end - # The version of the getopt library - VERSION = '1.4.3' - # Takes an array of switches. Each array consists of up to three # elements that indicate the name and type of switch. Returns a hash # containing each switch name, minus the '-', as a key. The value # for each key depends on the type of switch and/or the value provided # by the user. @@ -57,11 +57,11 @@ # Set our list of valid switches, and proper types for each switch switches.each{ |switch| valid.push(switch[0]) # Set valid long switches # Set type for long switch, default to BOOLEAN. - if switch[1].kind_of?(Fixnum) + if switch[1].kind_of?(Integer) switch[2] = switch[1] types[switch[0]] = switch[2] switch[1] = switch[0][1..2] else switch[2] ||= BOOLEAN @@ -73,11 +73,11 @@ # short switch, e.g. "--verbose" creates a "-v" synonym. The same # synonym can only be used once - first one wins. syns[switch[0]] = switch[1] unless syns[switch[1]] syns[switch[1]] = switch[0] unless syns[switch[1]] - switch[1] = [switch[1]] if RUBY_VERSION.to_f >= 1.9 + switch[1] = [switch[1]] switch[1].each{ |char| types[char] = switch[2] # Set type for short switch valid.push(char) # Set valid short switches } @@ -215,10 +215,10 @@ # # This allows users to refer to the long or short switch and get # the same value hash.dup.each{ |switch, val| if syns.keys.include?(switch) - syns[switch] = [syns[switch]] if RUBY_VERSION.to_f >= 1.9 + syns[switch] = [syns[switch]] syns[switch].each{ |key| hash[key] = val } end }