不是 Ruby 中的关键字
关键字“ not ”与其他关键字不同。 “not”关键字获取一个表达式并将其布尔值取反——因此,如果条件为真,它将返回false 。它像“! ” Ruby 中的运算符, “and”关键字和“!”之间的唯一区别运算符是“!”在所有运算符中具有最高优先级,而“not”是最低优先级之一。
句法:
not expression
示例 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
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
输出:
Incorrect username!
示例 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
输出:
Welcome to GeeksforGeeks