method

exclude?

v3.2.13 - Show latest stable - Class: String
exclude?(string)
public

The inverse of String#include?. Returns true if the string does not include the other string.

"hello".exclude? "lo" #=> false
"hello".exclude? "ol" #=> true
"hello".exclude? ?h   #=> false

1Note

Not only for strings, but arrays and hashes too

magnemg ยท Feb 18, 2015

exclude? is defined as !include?, meaning it is the exact opposite of include? . See the source.

This means that it works for Arrays and Hashes too, as well as for Strings.

It works for Arrays:

>> [nil].exclude?(nil)
=> false
>> [nil].include?(nil)
=> true
>> ["lala"].include?(nil)
=> false
>> ["lala"].exclude?(nil)
=> true

And for Hashes: >> params = {} => {} >> params[:db] = "lol" => "lol" >> params.exclude?(:db) => false >> params.include?(:db) => true >>