Check an Array for a Certain Item : include « Array « Ruby






Check an Array for a Certain Item


# The include? method returns true if the supplied parameter is in the array, 
# and false otherwise:


x = [1, 2, 3]
puts x.include?("x")
puts x.include?(3)

 








Related examples in the same category

1.Is an element in this array
2.include? with parenthesis