summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-21 04:27:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-21 04:27:06 +0000
commit564c80b10a116c49ac0dbcfe620e3f776c0d3845 (patch)
tree72d6bfaf40ae3ad0043c88122796d134720aba54 /lib
parentbec6d3b1b9a5fcc4ed37c98814e114066cfcc0a5 (diff)
* lib/optparse.rb: get rid of warnings.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/optparse.rb21
-rw-r--r--lib/optparse/date.rb17
-rw-r--r--lib/optparse/shellwords.rb2
-rw-r--r--lib/optparse/time.rb2
-rw-r--r--lib/optparse/uri.rb2
5 files changed, 30 insertions, 14 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index dfda6b2..54a92ce 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -844,8 +844,7 @@ Default options, which never appear in option summary.
--- OptionParser#to_s
Returns option summary string.
=end #'#"#`#
- def to_str; summarize(banner.to_s.sub(/\n?\z/, "\n")) end
- alias to_s to_str
+ def to_s; summarize(banner.to_s.sub(/\n?\z/, "\n")) end
=begin
--- OptionParser#to_a
@@ -1325,9 +1324,9 @@ Default options, which never appear in option summary.
: Object
any string, and no conversion. this is fall-back.
=end #'#"#`#
- accept(Object) {|s|s or s.nil?}
+ accept(Object) {|s,|s or s.nil?}
- accept(NilClass) {|s|s}
+ accept(NilClass) {|s,|s}
=begin
: String
@@ -1346,7 +1345,7 @@ Default options, which never appear in option summary.
hex = 'x[\da-f]+(?:_[\da-f]+)*'
octal = "0(?:[0-7]*(?:_[0-7]+)*|#{binary}|#{hex})"
integer = "#{octal}|#{decimal}"
- accept(Integer, %r"\A[-+]?(?:#{integer})"io) {|s| Integer(s) if s}
+ accept(Integer, %r"\A[-+]?(?:#{integer})"io) {|s,| Integer(s) if s}
=begin
: Float
@@ -1354,21 +1353,21 @@ Default options, which never appear in option summary.
=end #'#"#`#
float = "(?:#{decimal}(?:\\.(?:#{decimal})?)?|\\.#{decimal})(?:E[-+]?#{decimal})?"
floatpat = %r"\A[-+]?#{float}"io
- accept(Float, floatpat) {|s| s.to_f if s}
+ accept(Float, floatpat) {|s,| s.to_f if s}
=begin
: Numeric
Generic numeric format, and converts to (({Integer})) for integer
format, (({Float})) for float format.
=end #'#"#`#
- accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s| eval(s) if s}
+ accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s,| eval(s) if s}
=begin
: OptionParser::DecimalInteger
Decimal integer format, to be converted to (({Integer})).
=end #'#"#`#
DecimalInteger = /\A[-+]?#{decimal}/io
- accept(DecimalInteger) {|s| s.to_i if s}
+ accept(DecimalInteger) {|s,| s.to_i if s}
=begin
: OptionParser::OctalInteger
@@ -1376,7 +1375,7 @@ Default options, which never appear in option summary.
to (({Integer})).
=end #'#"#`#
OctalInteger = /\A[-+]?(?:[0-7]+(?:_[0-7]+)*|0(?:#{binary}|#{hex}))/io
- accept(OctalInteger) {|s| s.oct if s}
+ accept(OctalInteger) {|s,| s.oct if s}
=begin
: OptionParser::DecimalNumeric
@@ -1384,7 +1383,7 @@ Default options, which never appear in option summary.
(({Integer})) for integer format, (({Float})) for float format.
=end #'#"#`#
DecimalNumeric = floatpat # decimal integer is allowed as float also.
- accept(DecimalNumeric) {|s| eval(s) if s}
+ accept(DecimalNumeric) {|s,| eval(s) if s}
=begin
: TrueClass
@@ -1405,7 +1404,7 @@ Default options, which never appear in option summary.
: Array
List of strings separated by ","
=end #'#"#`#
- accept(Array) do |s|
+ accept(Array) do |s,|
if s
s = s.split(',').collect {|s| s unless s.empty?}
end
diff --git a/lib/optparse/date.rb b/lib/optparse/date.rb
new file mode 100644
index 0000000..c9f072f
--- /dev/null
+++ b/lib/optparse/date.rb
@@ -0,0 +1,17 @@
+require 'optparse'
+require 'date'
+
+OptionParser.accept(DateTime) do |s,|
+ begin
+ DateTime.parse(s) if s
+ rescue ArgumentError
+ raise OptionParser::InvalidArgument, s
+ end
+end
+OptionParser.accept(Date) do |s,|
+ begin
+ DateTime.parse(s) if s
+ rescue ArgumentError
+ raise OptionParser::InvalidArgument, s
+ end
+end
diff --git a/lib/optparse/shellwords.rb b/lib/optparse/shellwords.rb
index 75cb57b..0422d7c 100644
--- a/lib/optparse/shellwords.rb
+++ b/lib/optparse/shellwords.rb
@@ -3,4 +3,4 @@
require 'shellwords'
require 'optparse'
-OptionParser.accept(Shellwords) {|s| Shellwords.shellwords(s)}
+OptionParser.accept(Shellwords) {|s,| Shellwords.shellwords(s)}
diff --git a/lib/optparse/time.rb b/lib/optparse/time.rb
index 9f677a8..402cadc 100644
--- a/lib/optparse/time.rb
+++ b/lib/optparse/time.rb
@@ -1,7 +1,7 @@
require 'optparse'
require 'time'
-OptionParser.accept(Time) do |s|
+OptionParser.accept(Time) do |s,|
begin
(Time.httpdate(s) rescue Time.parse(s)) if s
rescue
diff --git a/lib/optparse/uri.rb b/lib/optparse/uri.rb
index 5bdcf57..024dc69 100644
--- a/lib/optparse/uri.rb
+++ b/lib/optparse/uri.rb
@@ -3,4 +3,4 @@
require 'optparse'
require 'uri'
-OptionParser.accept(URI) {|s| URI.parse(s) if s}
+OptionParser.accept(URI) {|s,| URI.parse(s) if s}