2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby caseの使い方

Last updated at Posted at 2019-06-14

Rubyの caseif の条件式が2者択一ではなく複数の選択肢から選択する道を選ぶ。

それに伴って when を使用して条件を作る。

order = "チャーハン"
case order
when "チャーハン"
  puts "750円です"
when "ラーメン"
 puts "600円です"
end

このように複数の条件でも選択肢を作ることができるのが case である。

2
1
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?