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?
classArraydefto_str"Hello from Array!"endend"#{[1,2,3,4,5]}"# => [1, 2, 3, 4, 5]
I believe String interpolation should call to_str before to_s
My main point here is that anything that happens within String interpolation is "implicitly" going to be a String. So shouldn't it call to_str before to_s on anything given?
classBdefto_str"Hello from B"endend"#{B.new}"# => "#<B:0x00000001969078>"
Should work as this does.
classBdefto_s"to_s"endend"#{B.new}"# => "to_s"
I also realize that having Ruby lookup two methods to_str and then to_s may slow it down and that we don't want to make it slower. Since Ruby is optimized for to_s being called first I think it would be okay to have to_str called second. Even though by definition you would think that an "implicit" method would be the first method called.