|Basic Lessons on Programming in Ruby
Lesson 4 - Ruby String Variables
What I assume you have:|
- A Linux / UNIX / Mac computer with Ruby installed. If you don't have this, you need to Google how to get Ruby installed to compile Ruby programs from the terminal or command line.
- The basic ability to run commands like ls , cp , vi (or some other command-line editor) , etc.
- You have completed lesson 3
- The ability to figure things out!
Lesson 4 - Ruby String Variables|
- This lesson will be a little different from the previous ones. We are going to use another website's lessons on a certain type of data you store in variables called string data or just strings. Go to this website and go through the 5 pages of lessons. In each page you are given an example of a short ruby program to illustrate what is being explained. For each example, save the program in your working ruby folder (where you have saved all your earlier lessons) with the program names "strings1.rb", "strings2.rb", and so on. If you are working on a mac, be sure to change the "shebang" line so that it will work on your mac ( "#!/bin/usr/ruby"). You need to read the lessons and study the example programs and their output carefully to understand what the author is getting at. This is very important and is something you will use later in your Ruby programming career!
- If anything looks different in your program output when you run your program, then check VERY carefully that you typed your program EXACTLY like the author's instructions!!!
- If you just can't get your program to produce the same output as the author's results, you probably need to email your instructor and ask him why before you proceed to the exercises below.
Summary of Lesson 4 on Ruby String Variables:|
- Create a program from each of the author's examples.
- Make each program executable, run it, and make sure the output looks EXACTLY like the author's given output.
- Notice how strings and operations on strings work. Also notice the significant difference between using single or double quotes with variables in Ruby.
Now, if you understood all this you should be able to do the following exercises:|
- Make a copy of each of your string program above and name it "lesson4ex1.rb" (cp strings1.rb lesson4ex1.rb). Do the same for all the programs.
- Modify each of your copies to use strings of your own choosing. Just try to pick strings and substrings to make your new example work similar to the way the author's example worked.
- If you are having any trouble, email your instructor!
Last updated on ... May 19, 2012
Created on ... May 19, 2012
These lessons were created by David Joyner. All rights reserved. You may use them to learn Ruby or teach Ruby to others as long as you DO NOT CHARGE for these materials! For any other use, permission may be asked of David Joyner at firstname.lastname@example.org.