Ruby introduced some common Array methods which have some built in Array classes in which some classes are listed below.
include?
Which is used to check whether the given argument is included in the array or not and which have question mark at the ending which means it returns the boolean value at the end the code below demonstrate the include? as shown.
[ruby]
irb: 001 > a = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
irb: 002 > a.include?(3)
=> true
irb: 003 > a.include?(6)
=> false
[/ruby]
each index
Each index iterates through an array just like the each method whenever variable represent the index number which opposed to the value at each index which passed through the index of the each element into block which shown in below code.
[ruby]
irb: 001 > a = [1, 2, 3, 4, 5]
=> [1, 2, 3, 4, 5]
irb: 002 > a.each_index { |i| puts "This is index #{i}" }
This is index 0
This is index 1
This is index 2
This is index 3
This is index 4
=> [1, 2, 3, 4, 5]
[/ruby]
sort
The sort method is a handy method to order an array and which resulted sorted array and the code below demonstrates the sorted array as shown.
[ruby]
irb :001 > a = [5, 3, 8, 2, 4, 1]
=> [5, 3, 8, 2, 4, 1]
irb :002 > a.sort
=> [1, 2, 3, 4, 5, 8]
[/ruby]