Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Array#==

(untyped other) -> bool
self == other_array → true or false

Returns whether both:

  • self and other_array are the same size.

  • Their corresponding elements are the same; that is, for each index i in (0...self.size), self[i] == other_array[i].

Examples:

Example
[:foo, 'bar', 2] == [:foo, 'bar', 2]   # => true
[:foo, 'bar', 2] == [:foo, 'bar', 2.0] # => true
[:foo, 'bar', 2] == [:foo, 'bar']      # => false # Different sizes.
[:foo, 'bar', 2] == [:foo, 'bar', 3]   # => false # Different elements.

This method is different from method Array#eql?, which compares elements using Object#eql?.

Related: see Methods for Comparing.

See also #<=> #[] #<< #[]= also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0