Issue #6130 has been updated by mame (Yusuke Endoh).

Status changed from Open to Assigned
Assignee set to matz (Yukihiro Matsumoto)

Thomas, you meant:

  class Foo
    def to_s; "foo"; end
  end
  x = Foo.new

  p "== #{ x } =="  #=> "== foo ==", as you want

  p x  #=> "foo", but you want: #<Foo:0xXXXX>

, right?  If so I agree, though it may be difficult in 2.0.

-- 
Yusuke Endoh <mame / tsg.ne.jp>
----------------------------------------
Feature #6130: inspect using to_s is pain
https://bugs.ruby-lang.org/issues/6130#change-25401

Author: trans (Thomas Sawyer)
Status: Assigned
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 2.0.0


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.




-- 
http://bugs.ruby-lang.org/