February 2, 2004 Intro to Ruby Slide #9
Prev Next

Arrays

Arrays can be initialized in a variety of ways:
     a1 = []         # empty array
     a2 = Array.new  # same thing

     a3 = [10, 20, 30]

     a4 = ['apple', 'cherry', 'pecan']
     a5 = %w(apple cherry pecan)  # same as a4

     a6 = [nil, nil, nil]
     a7 = Array.new(3)  # same as a6

     a8 = [0, 0, 0]
     a9 = Array.new(3, 0)  # same as a8


Prev Copyright © 2004 Walter C. Mankowski Next