@@ -20,7 +20,7 @@ The index can be used to access the objects in an Array. You will learn more
2020about using the index in the next unit "Accessing elements".
2121
2222An Array can hold all kinds of Ruby objects, such as Strings, Numbers, Booleans,
23- other Arrays, etc. The objects in an Array don‘t need to be of the same type:
23+ other Arrays, etc. The objects in an Array don‘t need to be of the same type.
2424An Array can hold all kinds of different objects (e.g. Strings, and Numbers) at the same time.
2525
2626Let‘s create some Arrays!
@@ -32,12 +32,13 @@ The shortest is surrounding a comma-separated list of objects with square bracke
3232
3333` [1, 'Mary', true] ` * # => [ 1, "Mary", true] *
3434
35- An Array is a Ruby object itself. If you ask for an Array‘s class with the ` class ` method:
35+ An Array is a Ruby object itself. If you ask for an Array‘s class with the ` class ` method
36+ you will get ` Array ` :
3637
3738` numbers = [1, 2, 3] `
3839` numbers.class ` * # => Array*
3940
40- you will get ` Array ` . An Array is an object of type * Array* .
41+ An Array is an object of type * Array* .
4142
4243Instead of using ` [] ` you can also use the the longer way and call the ` [] ` method
4344of the * Array* class:
@@ -46,33 +47,33 @@ of the *Array* class:
4647
4748## Creating an Array with #new
4849
49- Besides using ` [] ` , you can create an Array by instanciating an Array with the ` new ` method.
50- The ` new ` method accepts 2 optional parameters: The number of elements, and the element itself.
50+ Besides using ` [] ` , you can create an Array by instantiating an Array with the ` new ` method.
51+ The ` new ` method accepts two optional parameters: The number of elements, and the element itself.
5152
5253If you call ` new ` without any parameter it will create an empty Array:
5354
54- ` Array.new ` * # => [ ] *
55+ ` Array.new ` * # => [ ] *
5556
5657If you only define the first parameter as an Integer, it will use this Integer to define
5758the length of the new Array and will assign * nil* for each element:
5859
59- ` Array.new(2) ` * # => [ nil, nil]
60+ ` Array.new(2) ` * # => [ nil, nil] *
6061
6162If you pass an Array as first parameter it will return the defined Array:
6263
63- ` Array.new([1, 2, 3]) ` * # => [ 1, 2, 3] *
64+ ` Array.new([1, 2, 3]) ` * # => [ 1, 2, 3] *
6465
6566The actual interesting case is, if you pass both parameters.
6667It will create an array of the length given in the first parameter, with each element
6768being the second parameter. Here is an example:
6869
69- ` Array.new(3, 4.5) ` * # => [ 4.5, 4.5, 4.5] *
70- ` Array.new(2, ['a', 'b']) ` * # => [[ 'a', 'b'] , [ 'a', 'b']]
70+ ` Array.new(3, 4.5) ` * # => [ 4.5, 4.5, 4.5] *
71+ ` Array.new(2, ['a', 'b']) ` * # => [[ 'a', 'b'] , [ 'a', 'b']] *
7172
7273
73- Another way of creating an Array is calling ` Array() ` with 1 parameter:
74+ Another way of creating an Array is calling ` Array() ` with a single parameter:
7475
75- ` Array('banana') ` * # => [ "banana"] *
76+ ` Array('banana') ` * # => [ "banana"] *
7677
7778This will create a new Array with only the given value and is the same as calling ` ['banana'] ` .
7879
0 commit comments