2

I have a question: Is there any opposite method of .include? I know with unless, but I want to do it with if, can I? I tried with unless:

unless variable.include?("something")
#..
end

I want to do it with if, can I? I know .!include? but it didn't work(i don't really know if this method exists, but I saw it in this forum).

Ganesh
  • 1,924
  • 1
  • 18
  • 31
user9597197
  • 29
  • 1
  • 2
  • 1
    Short answer: Not in vanilla ruby, but `exclude?` exists in ActiveSupport - which is mainly used by Rails applications. – Tom Lord Apr 04 '18 at 14:15
  • 2
    `!include?` are actually _two_ methods: [`!`](http://ruby-doc.org/core-2.5.0/BasicObject.html#method-i-21) and `include?` You therefore have to write `!variable.include?` instead of `variable.!include?` – Stefan Apr 04 '18 at 14:43

1 Answers1

7
if !variable.include?("something")

in plain Ruby

if variable.exclude?("something")

in Rails

Ursus
  • 29,643
  • 3
  • 33
  • 50