Rather than an or
here, you want a logical &&
(and) because you are trying to find strings which match neither.
if ( !email_address.end_with?("@domain1.com") && !email_address.end_with?("@domain2.com"))
#Do Something
end
By using or
, if either condition is true, the whole condition will still be false.
Note that I am using &&
instead of and
, since it has a higher precedence. Details are well outlined here
From the comments:
You can build an equivalent condition using unless
with the logical or ||
unless email_address.end_with?("@domain1.com") || email_address.end_with?("@domain2.com")
This may be a bit easier to read since both sides of the ||
don't have to be negated with !
.