Section 2.18. Removing Trailing Newlines and Other Characters


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"





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

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net