* lib/optparse.rb (OptionParser#getopts): new methods.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10248 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2006-06-10 23:31:32 +00:00
Родитель 85c86a4e29
Коммит b55f60b59f
2 изменённых файлов: 55 добавлений и 1 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Sun Jun %-2d 08:30:33 2006 U-HUDIE\nobu,S-1-5-21-3746871489-166115513-3294629105-1005 <nobu@ruby-lang.org>
* lib/optparse.rb (OptionParser#getopts): new methods.
Sun Jun 11 07:27:11 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/rdoc/ri/ri_writer.rb: use String#ord.

Просмотреть файл

@ -1425,6 +1425,42 @@ class OptionParser
end
end
=begin
--- OptionParser#getopts(argv, single_options, *long_options)
--- OptionParser.getopts(argv, single_options, *long_options)
Wrapper methods for getopts.rb.
=end #'#"#`#
def getopts(argv, single_options, *long_options)
result = {}
single_options.scan(/(.)(:)?/) do |opt, val|
if val
result[opt] = nil
define("-#{opt} VAL") {|val| result[opt] = val}
else
result[opt] = false
define("-#{opt}") {result[opt] = true}
end
end if single_options
long_options.each do |arg|
opt, val = arg.split(':', 2)
if val
result[opt] = val.empty? ? nil : val
define("--#{opt} VAL") {|val| result[opt] = val}
else
result[opt] = false
define("--#{opt}") {result[opt] = true}
end
end
order!(argv)
result
end
def self.getopts(*args)
new.getopts(*args)
end
=begin private
--- OptionParser#visit(id, *args) {block}
@ -1528,7 +1564,6 @@ class OptionParser
env = ENV[env] || ENV[env.upcase] or return
parse(*Shellwords.shellwords(env))
end
=begin
= Acceptable argument classes
@ -1830,6 +1865,21 @@ Extends command line arguments array to parse itself.
def permute!() options.permute!(self) end
def parse!() options.parse!(self) end
=begin
--- OptionParser::Arguable#getopts(single_options, *long_options)
Substitution of getopts is possible as follows.
def getopts(*args)
($OPT = ARGV.getopts(*args)).each do |opt, val|
eval "$OPT_#{opt.gsub(/[^A-Za-z0-9_]/, '_')} = val"
end
rescue OptionParser::ParseError
end
=end #'#"#`#
def getopts(*args)
options.getopts(*args)
end
=begin private
Initializes instance variable.
=end #'#"#`#