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
Show source
Register or log in to add new notes.
February 18, 2015
0 thanks

Not only for strings, but arrays and hashes too

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
>>