diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-01-06 08:23:10 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-01-06 08:23:10 +0000 |
commit | 49684589cdbbbec3d43b73c1255f9c16171b055d () | |
tree | b3fbc07ffeda4a61ca34f64dea679c4a533f0e79 | |
parent | 4d0e0a38239b7558f3f7934076b6e3dd54b1547f (diff) |
optparse.rb: into kwdarg
* lib/optparse.rb (OptionParser#order!): add `into` optional keyword argument to store the results. [Feature #11191] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | lib/optparse.rb | 27 | ||||
-rw-r--r-- | test/optparse/test_optparse.rb | 11 |
4 files changed, 33 insertions, 13 deletions
@@ -1,3 +1,8 @@ Tue Jan 5 21:44:37 2016 SHIBATA Hiroshi <[email protected]> * ChangeLog: fix wrong class name. @@ -21,6 +21,9 @@ with all sufficient information, see the ChangeLog file or Redmine * CSV * Add a liberal_parsing option. [Feature #11839] === Stdlib compatibility issues (excluding feature bug fixes) === Built-in global variables compatibility issues @@ -1508,17 +1508,18 @@ XXX # # Returns the rest of +argv+ left unparsed. # - def order(*argv, &block) argv = argv[0].dup if argv.size == 1 and Array === argv[0] - order!(argv, &block) end # # Same as #order, but removes switches destructively. # Non-option arguments remain in +argv+. # - def order!(argv = default_argv, &nonopt) - parse_in_order(argv, &nonopt) end def parse_in_order(argv = default_argv, setter = nil, &nonopt) # :nodoc: @@ -1599,18 +1600,18 @@ XXX # Parses command line arguments +argv+ in permutation mode and returns # list of non-option arguments. # - def permute(*argv) argv = argv[0].dup if argv.size == 1 and Array === argv[0] - permute!(argv) end # # Same as #permute, but removes switches destructively. # Non-option arguments remain in +argv+. # - def permute!(argv = default_argv) nonopts = [] - order!(argv, &nonopts.method(:<<)) argv[0, 0] = nonopts argv end @@ -1619,20 +1620,20 @@ XXX # Parses command line arguments +argv+ in order when environment variable # POSIXLY_CORRECT is set, and in permutation mode otherwise. # - def parse(*argv) argv = argv[0].dup if argv.size == 1 and Array === argv[0] - parse!(argv) end # # Same as #parse, but removes switches destructively. # Non-option arguments remain in +argv+. # - def parse!(argv = default_argv) if ENV.include?('POSIXLY_CORRECT') - order!(argv) else - permute!(argv) end end @@ -64,4 +64,15 @@ class TestOptionParser < Test::Unit::TestCase assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/n")}) assert_equal(/foo/n, @reopt) end end |