summaryrefslogtreecommitdiff
path: root/lib/optparse.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-31 00:41:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-31 00:41:40 +0000
commite13bfb15096a9d12e93055fbe6526d15bc54e20c (patch)
tree79e1f4a58987ecce790629e61babb11303b8fa72 /lib/optparse.rb
parent1c37352f8a267f7ac5c540ab0b25bd0b56021a34 (diff)
* lib/optparse.rb (OptionParser::make_switch): NoArgument doesn't
override other styles. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/optparse.rb')
-rw-r--r--lib/optparse.rb16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 5be91eb27d..d7434ca4f2 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -158,6 +158,10 @@ Individual switch class.
raise ArgumentError, "#{arg}: incompatible argument styles\n #{self}, #{t}"
end
+ def self.pattern
+ NilClass
+ end
+
=begin private
--- OptionParser::Switch.new
=end #'#"#`#
@@ -294,6 +298,9 @@ Switch that takes no arguments.
end
def self.incompatible_argument_styles(*)
end
+ def self.pattern
+ Object
+ end
end
=begin private
@@ -336,7 +343,8 @@ Switch that can omit argument.
class PlacedArgument < self
def parse(arg, argv, &error)
- unless arg or argv.empty? or /\A-/ =~ argv[0]
+ unless arg
+ return nil, block, nil if argv.empty? or /\A-/ =~ argv[0]
arg = argv.shift
end
super(*parse_arg(arg, &error))
@@ -981,8 +989,8 @@ Default options, which never appear in option summary.
nolong << 'no-' + o
when /^--([^][=\s]*)(.+)?/
q, a = $1, $2
- o = notwice(a ? NilClass : TrueClass, klass, 'type')
if a
+ o = notwice(NilClass, klass, 'type')
default_style = default_style.guess(arg = a)
default_pattern, conv = search(:atype, o) unless default_pattern
end
@@ -999,8 +1007,8 @@ Default options, which never appear in option summary.
short << Regexp.new(q)
when /^-(.)(.+)?/
q, a = $1, $2
- o = notwice((a ? Object : TrueClass), klass, 'type')
if a
+ o = notwice(NilClass, klass, 'type')
default_style = default_style.guess(arg = a)
default_pattern, conv = search(:atype, o) unless default_pattern
end
@@ -1014,7 +1022,7 @@ Default options, which never appear in option summary.
end
end
- default_pattern, conv = search(:atype, Object) unless default_pattern
+ default_pattern, conv = search(:atype, default_style.pattern) unless default_pattern
s = if short.empty? and long.empty?
raise ArgumentError, "no switch given" if style or pattern or block
desc