diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | lib/optparse.rb | 2 | ||||
-rw-r--r-- | test/optparse/test_reqarg.rb | 12 |
3 files changed, 17 insertions, 1 deletions
@@ -1,3 +1,7 @@ +Sun Dec 21 12:23:16 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * lib/optparse.rb (SPLAT_PROC): fix for regexp. [ruby-dev:37514] + Sun Dec 21 10:43:10 2008 TAKANO Mitsuhiro (takano32) <tak@no32.tk> * sample/test.rb: rescue exception. diff --git a/lib/optparse.rb b/lib/optparse.rb index 0548a29cac..134f1cf3b1 100644 --- a/lib/optparse.rb +++ b/lib/optparse.rb @@ -996,7 +996,7 @@ class OptionParser end private :notwice - SPLAT_PROC = proc {|*a| a} + SPLAT_PROC = proc {|*a| next *a} # # Creates an OptionParser::Switch from the parameters. The parsed argument # value is passed to the given block, where it can be processed. diff --git a/test/optparse/test_reqarg.rb b/test/optparse/test_reqarg.rb index 4ce9dd6292..579794695a 100644 --- a/test/optparse/test_reqarg.rb +++ b/test/optparse/test_reqarg.rb @@ -60,4 +60,16 @@ module TestOptionParser::ReqArg assert_equal(%w"", no_error {@opt.parse!(%w"--opt=foo")}) assert_equal("foo", @flag) end + + class TestOptionParser::WithPattern < TestOptionParser + def test_pattern + pat = num = nil + @opt.def_option("--pattern=VAL", /(\w+)(?:\s*:\s*(\w+))?/) {|x, y, z| pat = [x, y, z]} + @opt.def_option("-T NUM", /\A[1-4]\z/) {|n| num = n} + no_error {@opt.parse!(%w"--pattern=key:val")} + assert_equal(%w"key:val key val", pat, '[ruby-list:45645]') + no_error {@opt.parse!(%w"-T 4")} + assert_equal("4", num, '[ruby-dev:37514]') + end + end end |