Section 2.33. Generating Successive Strings

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.

The Ruby Way(c) Solutions and Techniques in Ruby Programming
The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition)
ISBN: 0672328844
EAN: 2147483647
Year: 2004
Pages: 269
Authors: Hal Fulton

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: