🖥

Ruby | How to invert true and false

に公開
2023/08/29

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

Ruby | true と false を反転させる方法

About

About this translattion

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion