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

2 of 3

Assign Information to a Variable

Assigning information to a variable in Ruby is as easy as it was in the pseudocode . By using the assignment operator (the = character), you can store any information in a variable. In this example, a message to be printed to the screen is stored in the variable var1 and a number is stored in var2. The information in var1 and var2 could be used later by any Ruby statement.

 irb(main):001:0> var1 = "Ruby is fun and easy!"
 => "Ruby is fun and easy!"
 irb(main):002:0> var2 = 42
 => 42
 
  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.