Home > Articles > Programming > Ruby

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

2.32 Printing Special Characters

The dump method (like inspect) provides explicit printable representations of characters that may ordinarily be invisible or print differently. Here is an example:

s1 = "Listen" << "\007\007\007"   # Add three ASCII BEL characters
puts s1.dump                      # Prints: Listen\007\007\007
s2 = "abc\t\tdef\tghi\n\n"
puts s2.dump                      # Prints: abc\t\tdef\tghi\n\n
s3 = "Double quote: \""
puts s3.dump                      # Prints: Double quote: \"
  • + Share This
  • 🔖 Save To Your Account