Check if a value is present in an array in Ruby

3

How to check if a certain value is contained in an array in Ruby? For example, I want to know if 'A' is present in the ['A','B','C'] vector.

    
asked by anonymous 11.02.2015 / 22:57

1 answer

2

Use the include? method.

a = [ "a", "b", "c" ]
a.include?("b")   #=> true
a.include?("z")   #=> false
    
11.02.2015 / 22:57