ruby-changes:15208
From: nobu <ko1@a...>
Date: Mon, 29 Mar 2010 18:10:39 +0900 (JST)
Subject: [ruby-changes:15208] Ruby:r27089 (trunk): * lib/optparse.rb (Numeric): accept rationals.
nobu 2010-03-29 18:10:12 +0900 (Mon, 29 Mar 2010) New Revision: 27089 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27089 Log: * lib/optparse.rb (Numeric): accept rationals. Modified files: trunk/ChangeLog trunk/lib/optparse.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 27088) +++ ChangeLog (revision 27089) @@ -1,3 +1,7 @@ +Mon Mar 29 18:10:03 2010 Nobuyoshi Nakada <nobu@r...> + + * lib/optparse.rb (Numeric): accept rationals. + Mon Mar 29 15:10:39 2010 Nobuyoshi Nakada <nobu@r...> * lib/tempfile.rb (Tempfile#open): re-open with same mode and Index: lib/optparse.rb =================================================================== --- lib/optparse.rb (revision 27088) +++ lib/optparse.rb (revision 27089) @@ -1531,9 +1531,16 @@ # # 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. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/