Tyler DeWitt Tyler DeWitt - 1 year ago 457
Ruby Question

Is there an opposite of include? for Ruby Arrays?

I've got the following logic in my code:

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

is an array. Is there a method so I can avoid the

Ideally, this snippet would be:

if @players.does_not_include?(p.name) do

Answer Source
if @players.exclude?(p.name) do

ActiveSupport adds the exclude? method to both Array and String. This is not pure Ruby, but is used by a LOT of rubyists.