mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/optparse.rb (Numeric): accept rationals.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d0cb5c71ce
commit
b1b3e13570
2 changed files with 13 additions and 2 deletions
|
@ -1,3 +1,7 @@
|
|||
Mon Mar 29 18:10:03 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/optparse.rb (Numeric): accept rationals.
|
||||
|
||||
Mon Mar 29 15:10:39 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* lib/tempfile.rb (Tempfile#open): re-open with same mode and
|
||||
|
|
|
@ -1531,9 +1531,16 @@ class OptionParser
|
|||
|
||||
#
|
||||
# Generic numeric format, converts to Integer for integer format, Float
|
||||
# for float format.
|
||||
# for float format, and Rational for rational format.
|
||||
#
|
||||
accept(Numeric, %r"\A[-+]?(?:#{octal}|#{float})"io) {|s,| eval(s) if s}
|
||||
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.
|
||||
|
|
Loading…
Reference in a new issue