1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Using Variables in Ruby--Assign Information to a Variable

By

1 of 3

Open an IRB Window

This tutorial will teach you how to assign information to a variable and how to use variables in Ruby. You'll be using hands-on code, so if you haven't read about how to install Ruby or about running Ruby scripts from the command line, you should check out those tutorials first.

Here you'll be using the interactive Ruby prompt, so be sure to have an IRB window ready for experimentation. The code examples will be "logs" (or what was seen in an IRB window) of IRB sessions. You can either choose to copy the commands used in the log or experiment on your own. Remember, the whole point of the IRB is to allow for experimentation. If you make a mistake when experimenting with your variable, you can easily go back and fix it.

To start the IRB prompt, open your command-line and run the irb command. You'll be presented with the following prompt:


irb(main):001:0>
  1. About.com
  2. Technology
  3. Ruby
  4. Beginning Ruby
  5. Using Variables in Ruby--Assign Information to a Variable

©2014 About.com. All rights reserved.