From: "NARUSE, Yui" Date: 2009-11-21T14:43:14+09:00 Subject: [ruby-core:26854] Re: Internals: #to_s .vs. #to_str? 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. -- NARUSE, Yui