Abbey Workshop | ||||||||||
This how to covers the basics of using and creating strings in Ruby. It covers how to create strings, combine strings, insert variable data into strings, and here documents. Very basic stuff, but vital if you are getting started with scripts.
Below is a short Ruby scripts that demonstrates the basic use of strings. Explainations of the code follows after the example.
Download source for: strings.rb
Here are some of the highlights.
puts statement is used to write a sting to standard output. If you run the script, you will notice that a carriage return is automatically added to the end of the string.
puts statement on line 6.#{...} sequence represents a variable expression in Ruby. This expression is evaluated and the result is returned as a string. In this case, just the contents of test are returned. We could get a lot fancier with the expression I'm sure, but let's keep it simple for now.Well that covers the basic stuff. Additional string operators and ranges are covered in another HowTo.
Copyright © Abbey Workshop 2006