When trying to call String#+ with nil as an argument, you get the error "can't convert nil into String", which does not make sense (in fact seeming blatantly false) as nil.to_s, String(nil) etc. all return '' without errors.
Ideally, this method should use to_s to convert the argument, or else report an error along the lines of "can't append nil to string".
I support adding the 'implicit' word to the error message.
"no implicit conversion of nil into String"
I remember when I first encountered it, knowing to search for "implicit
conversion" would have helped me understand the difference between #to_s
and #to_str earlier.
[note: it's more than just implementing #to_str , there are other
implications for implicit casting]
"can't append nil to string (object doesn't respond to to_str)"
Looking at the implementation, a "can't append" would need some special code. A message such as ""can't convert nil into String (using to_str)" would be relatively easy to generate. I have attached a patch (not compiled or tested, sorry). This change would show up in many other places that use the same conversion logic, so let's make sure we really want it.
I am worried about implying that the user should add to_str, to_ary, etc. to fix this problem. Rarely is implementing these methods appropriate since they are used for objects that are intended to behave exactly as a String, Array, etc.
An error message that omitted mention of these methods can help prevent users from accidentally shooting themselves in the foot.
This issue was solved with changeset r38979.
Chris, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
object.c: Improve error for failed implicit conversions [Bug #7539]