So i have an array of @horses = []
that i start filling with some random horses.
How can i check if my @horses
array includes a horse that is already included (exists) in it?
I tried something like:
@suggested_horses = []
@suggested_horses << Horse.find(:first,:offset=>rand(Horse.count))
while @suggested_horses.length < 8
horse = Horse.find(:first,:offset=>rand(Horse.count))
unless @suggested_horses.exists?(horse.id)
@suggested_horses<< horse
end
end
I also tried with include?
but i saw it was for strings only. With exists I get the following error:
undefined method `exists?' for #<Array:0xc11c0b8>
So the question is how can I check if my array already has a horse included so that I dont fill it with the same horse?
Would be super grateful for any answers.