Project

General

Profile

Feature #12790

Updated by nobu (Nobuyoshi Nakada) about 8 years ago

`#inspect` is important for understanding "what I have" in irb/pry, and in [puts-debugging](https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html), and in ton of other cases. 

 Sadly, some of important stdlib classes (in my opinion) fail to provide concise and readable representation for `#inspect`. 

 Some examples below: 

 ## `BigDecimal` **BigDecimal** (important for representing money values, for example) 

 Current behavior: 

 ```ruby 
 #<BigDecimal:128d34f4,'0.25E2',9(18)> 
 #     ^             ^          ^        ^ 
 #     1             2          3        4 
 ``` 
 1. OK, this is reasonable 
 2. Do we really need object id here? As far as I can understand, developer is typically concerned only about numeric value identity, not object identity for bigdecimals. 
 3. OK, I understand about scientific representation, but it is hard to read (at least for me), and also single quotes around add to a confusion. 
 4. I'm not sure. Number of significant digits it is. So, what are the situation when you need to look at it constantly?.. 

 So, ideal behavior: 

 ```ruby 
 #<BigDecimal: 250> 
 # or, preserving num. of sig.dig. 
 #<BigDecimal: 250 digits: 9(18)> 
 # ...or something like this 

 # But for really large numbers it is still 
 #<BigDecimal: 1.5E35> 
 ``` 

 Side note: try to guess what `BigDecimal.new(2)**10_000` looks like?.. And whether this look is really useful for anything. 

 ## `Date` **Date** and `DateTime` **DateTime** 

 ```ruby 
 Date.today 
 # => #<Date: 2016-09-26 ((2457658j,0s,0n),+0s,2299161j)> 
 DateTime.now 
 # => #<DateTime: 2016-09-26T16:40:17+03:00 ((2457658j,49217s,186886101n),+10800s,2299161j)> 
 ``` 

 Maybe it is just me, but it does not look like part in parenthises (and double parenthises!) contain information of such real importance that it can change our perception of "what's going on"?.. If you work with current dates, it is just unnecessary; if you work with some really complicated historical dates, it is not enough, being too concise and enigmatic to give some understanding of epochs and calendars. 

 (And to add, it is awfully inconsistent with Time's `#inspect`, which does provide just `2016-09-26 17:03:59 +0300`.) 

Back