Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

not Keyword in Ruby

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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




# 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




# 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

My Personal Notes arrow_drop_up
Last Updated : 27 Jul, 2020
Like Article
Save Article
Similar Reads