summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-29 09:10:12 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-29 09:10:12 +0000
commitb1b3e13570c5d3cc6f04c27fab700198678e6d1f (patch)
treed8dc21f451be806cd214ef94a447080e305d1bfe /lib
parentd0cb5c71ce3f179f14fddf5241cf0dcfe1599123 (diff)
* lib/optparse.rb (Numeric): accept rationals.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/optparse.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 24ec91d78e..b07d91ef6c 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -1531,9 +1531,16 @@ class OptionParser
#
# Generic numeric format, converts to Integer for integer format, Float
- # for float format.
- #
- accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s,| eval(s) if s}
+ # for float format, and Rational for rational format.
+ #
+ real = "[-+]?(?:#{octal}|#{float})"
+ accept(Numeric, /\A(#{real})(?:\/(#{real}))?/io) {|s, d, n|
+ if n
+ Rational(d, n)
+ elsif s
+ eval(s)
+ end
+ }
#
# Decimal integer format, to be converted to Integer.