Project

General

Profile

Actions

Bug #11772

closed

Implicit conversion of Array in String interpolation does not call to_str

Added by danielpclark (Daniel P. Clark) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:71842]

Description

While providing an example in https://bugs.ruby-lang.org/issues/10930#note-7 I found that the implicit changing of an Array calls to_s without trying to_str first. Isn't String interpolation "implicitly" converting items to strings?

class Array
  def to_str
    "Hello from Array!"
  end
end

"#{[1,2,3,4,5]}"
# => [1, 2, 3, 4, 5]

I believe String interpolation should call to_str before to_s

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0