Array TypeError: can't convert Fixnum into String

后端 未结 6 1832
半阙折子戏
半阙折子戏 2021-01-01 10:04

I am experimenting with arrays, and am reading the book \"Beginning Ruby on Rails\" by Steve Holzner. I made the program:

array = [\'Hello\', \'there\', 1, 2         


        
6条回答
  •  攒了一身酷
    2021-01-01 10:43

    array2[1] is 6, which is a Fixnum. It doesn't know how to add itself to a string (which in this case is Banana. If you were to convert it to a string, it would work just fine.

    puts array2[0] + " " + array2[1].to_s
    

提交回复
热议问题