diff --git a/ChangeLog b/ChangeLog index 35009540c0..e5c5c3daf0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Mon Mar 29 18:10:03 2010 Nobuyoshi Nakada + + * lib/optparse.rb (Numeric): accept rationals. + Mon Mar 29 15:10:39 2010 Nobuyoshi Nakada * lib/tempfile.rb (Tempfile#open): re-open with same mode and 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. + # 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.