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.