Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. 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

Array elements are compared using eql? (items must also implement hash correctly).

Ruby version changes

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