From: Kurt Stephens Date: 2009-11-21T16:32:06+09:00 Subject: [ruby-core:26856] Re: Internals: #to_s .vs. #to_str? Does "123#{xyz}456" use xyz.to_s or xyz.to_str? NARUSE, Yui wrote: > Kurt Stephens wrote: >> Is there a description of the semantic differences between #to_s and >> #to_str? Are there any particular constraints on the results of these >> methods? Is it considered "legal" to return frozen Strings in some >> cases for either of the two? Is one used internal for implicit casts? >> >> I have some ideas that may reduce GC work and improve large String >> concatenation. >> >> I do remember a discussion about the differences between #to_a and >> #to_ary, but I don't quite remember why they are semantically different. > > to_int, to_str, to_ary, to_hash are fot implicit conversion. > path.to_str is called in path of following code, if path is not String: > open(path){|f| ... } > > to_i, to_s, to_a are explicit conversion. > > David Flanagan's Programing Language Ruby describes > those type conversion of Ruby at 3.8.7. >