Project

General

Profile

Actions

Feature #6130

closed

inspect using to_s is pain

Added by trans (Thomas Sawyer) almost 13 years ago. Updated about 12 years ago.

Status:
Closed
Target version:
[ruby-core:43238]

Description

Every time I define #to_s on a class I have to remember to also redefine #inspect. It's annoying and has led me to waste hours debugging b/c the errors that can occur from it often seem strange and unrelated.

I think #inspect should have an independent definition that outputs the class name, object_id and when possible instance variable settings, and should have nothing to do with #to_s by default. We developers can always alias it as such if it is appropriate.

The only exception should be for classes that have literal representation in Ruby, such as Array, String, Hash, etc. In those cases the #inspect should give the literal representation.


Files


Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #4453: Overriding #to_s changes #inspectClosedmame (Yusuke Endoh)03/01/2011Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0