0
0

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 3 years have passed since last update.

【Ruby】条件分岐 備忘録

Last updated at Posted at 2021-10-30

#目的
条件分岐 備忘録

#結論
とりあえず3種類あった。
if文
unless文
case文

timesメソッド #if文
a = 10
b = 20
if a > b
  puts "aはbより大きくない"
elsif a < b
  puts "aはbよりも小さい"
end
=>abより大きくない
timesメソッド #unless文
a = 10
b = 20
unless a > b
  puts "aはbより大きくない"
end
=>abより大きくない
timesメソッド #case文
array = [ "a", 1, nil ]
array.each do |item|
  case item
  when String
    puts "item is a String"
  when Numeric
    puts "item is a Numeric"
  else
    puts "item is something"
  end
end
=>item is a String
  item is a Numeric
  item is a something

#参考
たのしいRuby第5版

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?