Is there an opposite of include? for Ruby Arrays?

前端 未结 11 1809
孤街浪徒
孤街浪徒 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:32

    Try this, it's pure Ruby so there's no need to add any peripheral frameworks

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

    I was struggling with a similar logic for a few days, and after checking several forums and Q&A boards to little avail it turns out the solution was actually pretty simple.

提交回复
热议问题