1
0

More than 3 years have passed since last update.

ruby ifを1行で書く方法 まとめ by 初心者

Last updated at Posted at 2020-06-09

rubyのifを1行で各方法

true のみの場合

if a>0
  puts a
end

なら

puts a if a>0

if else の場合

if a>0
  puts a
else
  puts ""
end

なら

puts a>o ? a:"0"

みたいです。

さらに
if a>0
puts a
else
b=gets.chomp
end
なら

a>o ? puts a:b=gets.chomp

みたいです。

初心者の覚え書きとして^^

1
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
1
0