Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method · added in Ruby 3.1

Array#intersect?

ary.intersect?(other_ary) → true or false

Returns true if the array and other_ary have at least one element in common, otherwise returns false:

Example
a = [ 1, 2, 3 ]
b = [ 3, 4, 5 ]
c = [ 5, 6, 7 ]
a.intersect?(b)   #=> true
a.intersect?(c)   #=> false

Ruby version changes

  1. 3.1
See also #inspect #intersection #insert #join also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1