On Sat, Feb 01, 2003 at 12:51:35AM +0900, Chris Pine wrote:
> This is a small thing, but one that has ever-so-slightly annoyed me for
> quite some time now.  Instead of generating a TypeError on non-string input,
> why not just call to_s on it?  Isn't that always what you want?  Even as a
> newbie, all those years ago, I still felt like there was this inconsistency:
> 
>   print 'hi',5  #  No problem.
>   print "hi#{5}"#  All good.
>   print 'hi'+5  #  TypeError!
> 
> I always assumed there was some good reason for it (even if it was a bit
> confusing, and probably the source of fully half of my newbie mistakes, and
> which requires a disproportionate amount of my tutorial to explain...).
> However, if there is a good reason for it, I still don't see what it is.

What would you have Ruby do with this?

    print 5+' times'

Should Fixnum convert itself to a String if the right-hand argument is a
string? (In which case, String is somehow 'superior' to Fixnum, and a
whole hierarchy needs to be decided upon).

Or should it convert its right-hand argument to a Fixnum? Which probably
isn't what you want in this particular case, but might be in the different
case of

   a='10'
   print 5+a

If the interpreter tries to DWIM it's unlikely to get it right, so better
not even to try.

   print 5.to_s + ' times'     # that's what I mean
   print 5 + a.to_i            # that's what I mean

Regards,

Brian.