From: gabriele renzi Date: 2005-05-12T17:20:28+09:00 Subject: Re: Standard Library patches - rational, delegate Dave Burt ha scritto: > Hi, > > I have two small things I would like to see changed in the standard library: > delegate.rb > rational.rb > > I would like to hear from the list: > * how this might happen > * any comments on my changes > > The first is a small change to Delegate to prevent infinite recursion from > occurring when an object is assigned to delegate to itself. if this is a fix you can point out the bug on the ruby issue tracker on rubyforge, and attach the patch. Or you can post it on ruby-core. > The second are some enhancements to Rational, mainly to make it more > friendly with Floats and Strings, allowing rationals to be made like > Rational("2/3"), Rational("1.2e-10"), Rational(0.5), as well as adding to_r > methods to String and Float. This sounds more of an RCR, use RCRChive.net . > I've added approximation methods (similar to those recently discussed), > which are useful when trying to reduce an approximate Float to its original > representation, like this: > 1.6.to_r #=> Rational(3602879701896397, 2251799813685248) > 1.6.to_r.approximate #=> Rational(8, 5) > I've also fixed to_f so that it doesn't return NaN for rationals with large > denominators, and added radix selection in to_s like Integers have. I wonder if this would'nt cause a problem for new users which could get the false sense of security from float operations. Also, have you thought of intehration with BigDecimal ? And finaly.. I don't love the to_x methods (since there is so little room for them), but in general I think your patch makes sense.