Arrays in ruby are created by square brackets. The initial values can be placed in square brackets and separated by commas. array elements can be of different types and support addition and multiplication.
Ary = [1, 2, "3"]
Ary * 2 Returns [1, 2, "3", 1, 2, "3"]
Ary + ["Lee", "ho"] returns [1, 2, "3", "Lee", "ho"]
Ary [] returns [1, 2] and obtains two elements starting from position 0.
Ary [0 .. 2] returns [1, 2, "3"] From position 0 to position 2
Array support <operation means inserting an element at the end
Arrays and strings are converted to each other through join and split.
Ary. Join (",") returns "1, 2, 3"
"1, 2, 3". Split (",") Returns ["1", "2", "3"]
The visible array is very flexible.
Hash is also very flexible to use {} Structure
Hash = {"title" => "Hallo", 2 => "this is a hash "}
Hash ["title"] returns "Hallo"
A = "title"
Hash [a] returns Hallo
Hash [3] = "sample" adds an element whose key is 3 and value is "sample"
Hash. delete 3 Delete elements whose key is 3