0
0

More than 3 years have passed since last update.

if・unlessを一行で ❏Ruby❏

Last updated at Posted at 2019-11-22

後置なんちゃらというやつです。
処理を先に、条件式を後ろにすることでスマートに書けます。

後置if

num = 1
puts "0より大きいよ!" if num > 0

後置unless

num = 1
puts "0じゃないよ!" unless num == 0

it'sスマート!
ただし、条件式が複雑な時は普通の方を使いましょう。



ではまた!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0