Now, I'm learning Ruby and I don't understand the difference between the logical negation operators ! and not.
If I try this assignment with the ! operator
then it works, but this similar thing with not doesn' work
Why I get the error unexpected kNOT ???
However using not in logical condition (without assignment) works good
What is the difference between the operators ! and not? Who can explain this strange behaviour of the operator not?
If I try this assignment with the ! operator
Code:
irb(main):001:0> x = true
=> true
irb(main):002:0> t = !x
=> false
Code:
irb(main):001:0> x = true
=> true
irb(main):002:0> t = not x
SyntaxError: compile error
(irb):2: syntax error, unexpected kNOT
t = not x
^
from (irb):2
irb(main):003:0> t = not(x)
SyntaxError: compile error
(irb):3: syntax error, unexpected kNOT
t = not(x)
^
from (irb):3
However using not in logical condition (without assignment) works good
Code:
irb(main):001:0> something = false
=> false
irb(main):002:0> if not(something)
irb(main):003:1> puts "It is False"
irb(main):004:1> else
irb(main):005:1* puts "It is True"
irb(main):006:1> end
It is False
=> nil