ruby on rails - How do I check to see if my array includes an object? -
I have an array @hors = []
which fills me with some random horses.
How can I check that my @horse
array includes a horse which is already present (present)?
I tried to do something like this:
@ suggested_hors = [] @ suggested_hours & lt; & Lt; Horse.find (: First ,: offset => Rand (Horse Quarter)) while @ suggested_horses.length & lt; 8 horses = horses. Search (: first ,: offset = & gt; rand (Horse Cuba)) until @ suggested_horses.exists? (MAR.ID) @ Get Recommended & lt; & Lt; End of the horse end
I also tried to include ?
But I noticed that this was only for string. Is present?
I get the following error:
Undefined method 'exists?' # for; Hey: 0xc11c0b8 & gt;
So the question is how can I check that my array already contains a "horse" so that I can not fill it with the same horse?
Ruby does not have an array exists?
Method. And they've got the method to do something like
as long as @ suggested_horses.include? (Horse) @ suggested_hours & lt; & Lt; The end of the horse
should work out of the box.
Comments
Post a Comment