(The blockquote style does not look so well so I just pasted directly, but these are all quoted from the links in the bottom of this page)
You should not implement to_str
unless your object acts like a string, rather than just having a string representation. The only core class that implements to_str
is String itself.
[to_i and to_s] are not particularly strict: if an object has some kind of decent representation as a string, for example, it will probably have a to_s method… [to_int and to_str] are strict conversion functions: you implement them only if you object can naturally be used every place a string or an integer could be used.
to_str
is used by methods such as String#concat
to convert their arguments to a string. Unlike to_s, which is supported by almost all classes, to_str
is normally implemented only by those classes that act like strings. Of the built-in classes, only Exception
and String
implement to_str