Is there an opposite of include? for Ruby Arrays?

前端 未结 11 1854
孤街浪徒
孤街浪徒 2020-12-23 13:11

I\'ve got the following logic in my code:

if !@players.include?(p.name)
  ...
end

@players is an array. Is there a method so

11条回答
  •  长情又很酷
    2020-12-23 13:22

    I was looking up on this for myself, found this, and then a solution. People are using confusing methods and some methods that don't work in certain situations or not at all.

    I know it's too late now, considering this was posted 6 years ago, but hopefully future visitors find this (and hopefully, it can clean up their, and your, code.)

    Simple solution:

    if not @players.include?(p.name) do
      ....
    end
    

提交回复
热议问题