🖥
Ruby | How to invert true and false
set true to false
!(true) # => false
set false to true
!(false) # => true
What time is it useful?
Useful when you want to return the opposite result. For example, if you decide not to be a woman but a man.
With if
Redundant.
class Person def is_man? if is_woman return false else return true end end end
If you use!
I can write more concisely.
class Person def is_man? !(is_woman?) end end
Original by
About
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-04-16
Discussion