From: Mathieu Bouchard Date: 2004-03-07T01:17:43+09:00 Subject: Re: Possible strangeness in Numeric On Sat, 6 Mar 2004, Yukihiro Matsumoto wrote: > In message "Possible strangeness in Numeric" > on 04/03/06, Dave Thomas writes: > |I suggest that the to_int implementation should be moved from Numeric > |to Integer. > This has been changed several times. Some feel just like you, whereas > others feel integer arguments should accept floating point values. > I'm happy to discuss and get the final decision. Have you tried something like this?: class Numeric def to_int x=self.to_i raise "not a representation of an integer" if x!=self x end end class Float; remove_method :to_int; end class Integer; remove_method :to_int; end So (2.5).to_int raises, but (2.0).to_int returns 2, and Rational(4,3).to_int raises, but Rational(6,3).to_int returns 2. Complex(2.0,0.0).to_int, however, doesn't work, because Complex doesn't have a #to_f nor a #to_i at all. I am wondering what a good default #to_f for Complex would be. It wouldn't be modulus because then Complex(-2.0,0).to_f == +2.0, which would be really bad. Taking the real part sounds more reasonable. I don't really have any other ideas. ________________________________________________________________ Mathieu Bouchard http://artengine.ca/matju