Ruby Language
Goals
Steps
Step 1
irb3.0.3 :001 >Step 2
Next try some simple math that's built into Ruby. Type these lines into IRB:3 + 3 7 * 6Step 3
my_number = 5 my_fruit = 'kiwi'Step 4
my_variable + 2 my_variable * 3Step 5
fruits = ["kiwi", "strawberry", "plum"]Step 6
Type this in the shell:fruits = fruits + ["orange"] fruits = fruits - ["kiwi"]Step 7
7.class "kiwi".class fruits.classStep 8
fruits.length fruits.firstfruits.methodsfruits.methods.sortStep 9
fruits = ["kiwi", "strawberry", "plum"] fruits.each do |fruit| puts fruit endStep 10
if my_number > 1 puts "YAY!" endif my_number > 1 puts "YAY!" else puts "BOO!" endStep 11
def pluralize(word) word + "s" end pluralize("kiwi") pluralize("apple") pluralize("knife")Step 12
def my_opinion(fruits) fruits.each do |fruit| if fruit == "pizza" puts "pizza is the best!!!" else puts pluralize(fruit) + " are pretty good, I guess..." end end end my_opinion(["apple", "pizza", "orange"])
Next Step:
Go on to Getting Started