Project

General

Profile

Feature #17170

Updated by sawa (Tsuyoshi Sawada) 6 months ago

Hi at the ruby team, 

 I'd like to suggest to enhance `Numeric` Numeric 
 to provide two new class methods, 
 which shall be: `zero` zero and `one`. one 

 - `Integer.zero` Integer.zero shall be equal to `Integer(0)` Integer(0) 
 - `Float.zero` Float.zero shall be equal to `Float(0)` Float(0) 
 - `BigDecimal.zero` BigDecimal.zero shall be equal to `BigDecimal(0)` BigDecimal(0) 
 - `Complex.zero` Complex.zero shall be equal to `Complex(0)` Complex(0) 

 Likewise for `one`, one, you get the idea. 

 `Numeric` Numeric already provides `#zero?`, #zero? 
 so `Numeric.zero.zero?` Numeric.zero.zero? shall always be `true`. true. 

 I expect this to make code more explicit. 
 And it would save safe a pair of braces. 
 (Don't laugh--This (don't laugh -- this really got me here.) here) 

 --- 

 Maybe you already considered that for 3.0, which 
 that would be a late addition. 

 Ruby ruby shines in teaching mathematics. You 
 you know, we have zero and one there. 

 I use ruby in the financial realm. 
 For me, me it's important to write `BigDecimal.zero`. BigDecimal.zero 

 --- 

 I expect that the new API api should not break existing code. 
 We could try it with Rails first. Let's rails first, 
 let's ask them. 

 


 It would be nice to have that in [Rails] rails 3. 

 ~eike 
 









































Back