ruby-changes:9421
From: yugui <ko1@a...>
Date: Wed, 24 Dec 2008 13:09:49 +0900 (JST)
Subject: [ruby-changes:9421] Ruby:r20959 (ruby_1_9_1): merges r20895 and r20902 from trunk into ruby_1_9_1.
yugui 2008-12-24 13:09:31 +0900 (Wed, 24 Dec 2008) New Revision: 20959 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=20959 Log: merges r20895 and r20902 from trunk into ruby_1_9_1. * lib/optparse.rb (SPLAT_PROC): fix for regexp. [ruby-dev:37514] Modified files: branches/ruby_1_9_1/ChangeLog branches/ruby_1_9_1/lib/optparse.rb branches/ruby_1_9_1/test/optparse/test_reqarg.rb Index: ruby_1_9_1/ChangeLog =================================================================== --- ruby_1_9_1/ChangeLog (revision 20958) +++ ruby_1_9_1/ChangeLog (revision 20959) @@ -1,3 +1,11 @@ +Sun Dec 21 14:55:18 2008 Nobuyoshi Nakada <nobu@r...> + + * lib/optparse.rb (SPLAT_PROC): splat values by hand. + +Sun Dec 21 12:23:16 2008 Nobuyoshi Nakada <nobu@r...> + + * lib/optparse.rb (SPLAT_PROC): fix for regexp. [ruby-dev:37514] + Mon Dec 22 15:25:03 2008 Yuki Sonoda (Yugui) <yugui@y...> * thread.c (Thread#set_trace_func, #add_trace_func): removed. Index: ruby_1_9_1/lib/optparse.rb =================================================================== --- ruby_1_9_1/lib/optparse.rb (revision 20958) +++ ruby_1_9_1/lib/optparse.rb (revision 20959) @@ -996,7 +996,7 @@ end private :notwice - SPLAT_PROC = proc {|*a| a} + SPLAT_PROC = proc {|*a| a.length <= 1 ? a.first : a} # # Creates an OptionParser::Switch from the parameters. The parsed argument # value is passed to the given block, where it can be processed. Index: ruby_1_9_1/test/optparse/test_reqarg.rb =================================================================== --- ruby_1_9_1/test/optparse/test_reqarg.rb (revision 20958) +++ ruby_1_9_1/test/optparse/test_reqarg.rb (revision 20959) @@ -60,4 +60,16 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/