Check if a value is present in a Ruby array

Asked

Viewed 1,596 times

3

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

1 answer

2


Use the method include?.

a = [ "a", "b", "c" ]
a.include?("b")   #=> true
a.include?("z")   #=> false

Browser other questions tagged

You are not signed in. Login or sign up in order to post.