From: Ralph Mason Date: 2001-11-21T09:32:26+09:00 Subject: [ruby-talk:25968] Re: string concat and .to_s Although as a bit of an anomaly it works with arrays. 's'+[1] "Dave Thomas" wrote in message > Why does puts(1) work, but puts('s'+1) not work? It gives: > > > > The error message makes it clear that it knows it should be converted to a > > string. Why didn't + method just do a .to_s to the parameter coming in? > > #puts knows that it it's parameter is not a string, it can call > to_s. However, in general, matz decided that allowing arithmetic on > arbitrary strings leads to too many errors, so he did not add > string coercion to the standard arithmetic operators. You can always > add it if you'd like (putting it into a file you could require would > make it reusable across all your programs). >