Issue #12174 has been reported by Tsuyoshi Sawada.

----------------------------------------
Bug #12174: Interpolation ignores `to_s` (and `inspect`) when `to_s` is defined to `nil`.
https://bugs.ruby-lang.org/issues/12174

* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
When `to_s` is defined to return `nil`, interpolation prints the original inspection.

~~~RUBY
class A
  def to_s; end
end

puts "#{A.new}" # => #<A:0x007f4edf19d720>
~~~

It even ignores an overwritten `inspect` definition.


~~~RUBY
class A
  def to_s; end
  def inspect; "foo" end
end

puts "#{A.new}" # => #<A:0x007f8176c09050>
~~~



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

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>