==

==(other)
Instance Public methods

Equivalent to Array#==. Returns true if the two arrays contain the same number of elements and if each element is equal to the corresponding element in the other array, otherwise returns false.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Person < ActiveRecord::Base
  has_many :pets
end
 
person.pets
# => [
#      #<Pet id: 1, name: "Fancy-Fancy", person_id: 1>,
#      #<Pet id: 2, name: "Spook", person_id: 1>
#    ]
 
other = person.pets.to_ary
 
person.pets == other
# => true
 
other = [Pet.new(id: 1), Pet.new(id: 2)]
 
person.pets == other
# => false
doc_ruby_on_rails
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.