Home > Articles > Programming > Ruby

📄 Contents

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

2.32 Printing Special Characters

The dump method provides explicit printable representations of characters that may ordinarily be invisible or print differently:

s1 = "Listen" << 7 << 7 << 7   # 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: \"

For the default setting of $KCODE, dump behaves the same as calling inspect on a string. The $KCODE variable is discussed in Chapter 4.

  • + Share This
  • 🔖 Save To Your Account