From: yasnet21+ruby@... Date: 2018-06-14T15:14:53+00:00 Subject: [ruby-core:87493] [Ruby trunk Feature#12602] Add NilClass#to_d Issue #12602 has been updated by isayajin (Isay Sosa). Any updates about this feature? I ended up adding the `#to_d` by monkey patching `NilClass`, but I would like this feature to get merged. ---------------------------------------- Feature #12602: Add NilClass#to_d https://bugs.ruby-lang.org/issues/12602#change-72497 * Author: Domon (Chun-wei Kuo) * Status: Assigned * Priority: Normal * Assignee: mrkn (Kenta Murata) * Target version: ---------------------------------------- `bigdecimal/util` adds a `#to_d` method to many native classes, as a shortcut to converting them to `BigDecimal`, e.g. ```ruby require 'bigdecimal' require 'bigdecimal/util' 1.23.to_d # => # ``` However, `#to_d` is not added to `NilClass`: ```ruby nil.to_d # => NoMethodError: undefined method `to_d' for nil:NilClass ``` While `to_i`, `to_f`, etc. works on `nil`: ```ruby nil.to_i # => 0 nil.to_f # => 0.0 ``` I think it is reasonable to make `to_d` behave more like its counterparts. Therefore, I tried implementing the `NilClass#to_d` method in `bigdecimal/util` with a test. The method always returns `0` in `BigDecimal`. Please see attached patch. Thanks! :) ---Files-------------------------------- add-nil-to-d.patch (1.34 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: