🖥

Ruby | if and unless can both be written on one line

に公開

Example

 'I found a truth.' if true unless false # => 'I found a truth.' 

Use

You don't have to write extra negation (!) To connect the conditional expressions. The meaning becomes clear. The following is a redundant example.

 'I found a truth.' if true && !false # => 'I found a truth.' 

environment

  • ruby 2.3.0

Original by

Ruby | if と unless は一行に両方書ける

About

About this translattion

チャットメンバー募集

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

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

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion