Home > Articles > Programming > Ruby

📄 Contents

  • Print
  • + Share This
This chapter is from the book

2.17 Appending an Item Onto a String

The append operator << can be used to append a string onto another string. It is "stackable" in that multiple operations can be performed in sequence on a given receiver.

str = "A"
str << [1,2,3].to_s << " " << (3.14).to_s
# str is now "A123 3.14"

If a Fixnum in the range 0..255 is specified, it will be converted to a character:

str = "Marlow"
str << 101 << ", Christopher"
# str is now "Marlowe, Christopher"
  • + Share This
  • 🔖 Save To Your Account