Is there an opposite of include? for Ruby Arrays ?

Is there an opposite of include? for Ruby Arrays ?

Add Comment


  • 3 Answer(s)

    Ruby Array: 

    if @players.exclude?(p.name)
    ...
    end
    

    The exclude? method to Array, Hash, and String. This is not pure Ruby, but is used by a LOT of rubyists.

    For More details check this link: Active Support Core Extensions

     

    Answered on January 7, 2019.
    Add Comment

    The Ruby Style Guide  on similar techniques: 

    unless @players.include?(p.name)
    ...
    end
    

    Answered on January 7, 2019.
    Add Comment

    if @players.exclude?(p.name)

    end

    Answered on March 5, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.