 
 This page contains automated test results for code from O'Reilly's Ruby Cookbook. If this code looks interesting or useful, you might want to buy the whole book.
| Arrays | ||
|---|---|---|
| Code | Expected | Actual | 
| a1 = [] | [] | [] | 
| a2 = [1, 2, 3] | [1, 2, 3] | [1, 2, 3] | 
| a3 = [1, 2, 3, 'a', 'b', 'c', nil] | [1, 2, 3, "a", "b", "c", nil] | [1, 2, 3, "a", "b", "c", nil] | 
| n1 = 4 n2 = 6 sum_and_difference = [n1, n2, n1+n2, n1-n2] | [4, 6, 10, -2] | [4, 6, 10, -2] | 
| %w{1 2 3} | ["1", "2", "3"] | ["1", "2", "3"] | 
| %w{The rat sat
   on the mat}                           | ["The", "rat", "sat", "on", "the", "mat"] | ["The", "rat", "sat", "on", "the", "mat"] | 
| a = [1, 2, 3] | [1, 2, 3] | [1, 2, 3] | 
| a << 4.0 | [1, 2, 3, 4.0] | [1, 2, 3, 4.0] | 
| a << 'five' | [1, 2, 3, 4.0, "five"] | [1, 2, 3, 4.0, "five"] | 
| a = [1,2,3] | [1, 2, 3] | [1, 2, 3] | 
| a << [4, 5, 6] | [1, 2, 3, [4, 5, 6]] | [1, 2, 3, [4, 5, 6]] | 
| a << a | [1, 2, 3, [4, 5, 6], [...]] | [1, 2, 3, [4, 5, 6], [...]] | 
| a = [1, 2, 3, [4, 5, 6]] a.size | 4 | 4 | 
| a << a | [1, 2, 3, [4, 5, 6], [...]] | [1, 2, 3, [4, 5, 6], [...]] | 
| a.size | 5 | 5 | 
| a[0] | 1 | 1 | 
| a[3] | [4, 5, 6] | [4, 5, 6] | 
| a[3][0] | 4 | 4 | 
| a[3].size | 3 | 3 | 
| a[-2] | [4, 5, 6] | [4, 5, 6] | 
| a[-1] | [1, 2, 3, [4, 5, 6], [...]] | [1, 2, 3, [4, 5, 6], [...]] | 
| a[a.size-1] | [1, 2, 3, [4, 5, 6], [...]] | [1, 2, 3, [4, 5, 6], [...]] | 
| a[-1][-1] | [1, 2, 3, [4, 5, 6], [...]] | [1, 2, 3, [4, 5, 6], [...]] | 
| a[-1][-1][-1] | [1, 2, 3, [4, 5, 6], [...]] | [1, 2, 3, [4, 5, 6], [...]] |