开发者

if statement in ruby

开发者 https://www.devze.com 2023-01-05 01:38 出处:网络
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?a == b returns true if they are equal.

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?


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.


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


See here Ruby Logical Operators for a discussion.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消