Section 2.21. Embedding Expressions Within Strings


2.20. Repeating Strings

In Ruby, the multiplication operator (or method) is overloaded to enable repetition of strings. If a string is multiplied by n, the result is n copies of the original string concatenated together:

etc = "Etc. "*3                        # "Etc. Etc. Etc. " ruler = "+" + ("."*4+"5"+"."*4+"+")*3 # "+....5....+....5....+....5....+"





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

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