On Feb 23, 9:00 am, "tchick" <monsorno-nos... / gmx.de> wrote: > Hi *, > > I like to concatenate a string out of some variables, some of which > are nil. Instead of getting always a "can't convert nil into String > (TypeError)" message, I would like to have "nil" appended to my > string, as in Java null objects are printed as null in Strings. > Something like this: > > words = Hash.new > words[0]="one" > allWords = "all words:" > allWords << words[0] > allWords << words[1] > # --> can't convert nil into String (TypeError) > > Is this possible? Or how can I handle nil objects for this case? If you're adventerous (ie. your code is essentially standalone and in no danger of effecting others): class NilClass def to_str "" end end T.