tags:

views:

79

answers:

3

How does this statement work?

if not a==b
  puts "amit"
else
  puts "ramit"
end

Could anybody tell me the use of not operator here?

+2  A: 

See here Ruby Logical Operators for a discussion.

not a==b is the same as !(a==b) they are both acceptable.

Preet Sangha
step i did nt get what u wrote if you just highlight your code and press 'control key' and letter 'K' together, it will automatically indent it for you what does that mean
amit singh tomar
+2  A: 

if not a==b is equal to if !(a==b), if a!=b, unless a==b or unless not a!=b

If you don't know this I would recommend reading "The Well-Grounded Rubyist" from David A. Black

jigfox
`if !(a!=b)` this ones wrong. You meant `if !(a==b)`.
sepp2k
@sepp2k: Sure, Thanks!
jigfox
`unless !(a==b)` is also wrong.
Tomas Markauskas
@Thomas, sorry about that, thanks for your tipp
jigfox
+3  A: 

a == b returns true if they are equal.

The not operator inverts the answer, so:

not a == b returns true if they are NOT equal.

Tom Gullen