summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--lib/optparse.rb18
2 files changed, 14 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 4fdec0833e..cfa44fb020 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Sun Oct 1 23:12:19 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * lib/optparse.rb (OptionParser#make_switch): pass arguments directly.
+
Sat Sep 30 15:12:25 2006 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date.rb, lib/date/format.rb: updated based on date2 3.9.4.
diff --git a/lib/optparse.rb b/lib/optparse.rb
index f790054ec2..2c034043e0 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -398,6 +398,7 @@ class OptionParser
self
end
+ # :nodoc:
def add_banner(to)
unless @short or @long
s = desc.join
@@ -406,6 +407,7 @@ class OptionParser
to
end
+ # :nodoc:
def match_nonswitch?(str)
@pattern =~ str unless @short or @long
end
@@ -425,7 +427,7 @@ class OptionParser
#
# Raises an exception if any arguments given.
#
- def parse(arg, argv, &error)
+ def parse(arg, argv)
yield(NeedlessArgument, arg) if arg
conv_arg(arg)
end
@@ -603,8 +605,7 @@ class OptionParser
def search(id, key)
if list = __send__(id)
val = list.fetch(key) {return nil}
- return val unless block_given?
- yield(val)
+ block_given? ? yield(val) : val
end
end
@@ -642,6 +643,7 @@ class OptionParser
end
end
+ # :nodoc:
def add_banner(to)
list.each do |opt|
if opt.respond_to?(:add_banner)
@@ -1055,7 +1057,7 @@ class OptionParser
# Handler for the parsed argument value. Either give a block or pass a
# Proc or Method as an argument.
#
- def make_switch(*opts, &block)
+ def make_switch(opts, block = nil)
short, long, nolong, style, pattern, conv, not_pattern, not_conv, not_style = [], [], []
ldesc, sdesc, desc, arg = [], [], []
default_style = Switch::NoArgument
@@ -1175,7 +1177,7 @@ class OptionParser
end
def define(*opts, &block)
- top.append(*(sw = make_switch(*opts, &block)))
+ top.append(*(sw = make_switch(opts, block)))
sw[0]
end
@@ -1190,7 +1192,7 @@ class OptionParser
alias def_option define
def define_head(*opts, &block)
- top.prepend(*(sw = make_switch(*opts, &block)))
+ top.prepend(*(sw = make_switch(opts, block)))
sw[0]
end
@@ -1204,7 +1206,7 @@ class OptionParser
alias def_head_option define_head
def define_tail(*opts, &block)
- base.append(*(sw = make_switch(*opts, &block)))
+ base.append(*(sw = make_switch(opts, block)))
sw[0]
end
@@ -1786,5 +1788,5 @@ if $0 == __FILE__
Version = OptionParser::Version
ARGV.options {|q|
q.parse!.empty? or puts "what's #{ARGV.join(' ')}?"
- } or exit 1
+ } or abort(ARGV.options.to_s)
end