Good example of antiquity of some Core Ruby classes by jgn on Tuesday, September 22, 2009 in Technology

A common pattern in Ruby is to call .to_s on an object when you want a String, even if the object itself might be a String. So, e.g., if you are getting NoMethodErrors on nils when you need a String, you might call .to_s to convert that nil into a String ('').

Well, you might want to do the same thing to convert Floats to BigDecimals. But guess what? BigDecimal doesn't include a .to_d method! Oops. The BigDecimal class must be so old that this idiom hadn't evolved.

comments powered by Disqus