The keyword “not” is different from the others. The "not" keyword gets an expression and inverts its boolean value – so given a true condition it will return false. It works like "!" operator in Ruby, the only difference between "and" keyword and "!" operator is “!” has the highest precedence of all operators, and “not” one of the lowest.
Syntax:
not expression
Example 1:
# Ruby program to illustrate not keyword
uname = "geeks"
# Using not keyword
if not(uname == "Geeks" )
puts "Incorrect username!"
else
puts "Welcome, GeeksforGeeks!"
end
Output:
Incorrect username!
Example 2:
# Ruby program to illustrate not keyword
uname = "Geek"
password = "Wel123"
number = 123
if not(uname == "Geek" &&
password == "Wel123" &&
number == 123)
puts "Hey, Incorrect Credentials"
else
puts "Welcome to GeeksforGeeks"
end
Output:
Welcome to GeeksforGeeks