From: William Djaja Tjokroaminata Date: 2002-10-22T22:56:55+09:00 Subject: Re: Ruby/Tk newbie question Hi Andrew, As also already responded by other people, Ruby by default does not call the "to_s" method for a string in its "+" method. In this regard, Ruby wants you to be explicit about what you are doing. But of course, nothing prevents you to redifine the string "+" method: a = 'aString' b = 1 #puts a + b # -> "failed to convert Fixnum into String" class String alias oldPlus + def +(anObj) oldPlus(anObj.to_s) end end puts a + b # -> "aString1" Or, as already been pointed out, you can just put the variables in #{} in a double-quoted string, in which case the objects' to_s methods are automatically called for you. (Well... Ruby is really not "there is only one way to do it", but perhaps as some people call it, "there is always the best way to do it" :) ) Regards, Bill =========================================================================== andrew delboy wrote: > Is there a way to concatonate strings without having to use the x.to_s method? > In other words, because "+" is a string to start the expression, wouldnt the > plus operator actually be the '+' method within the string object? And thus > wouldnt the string want to use 'string values' of the objects they are concatonating? > Can we use the shortcut of > geom = "+" + x + "+" + y > ?? > Thanks > --Andrew