LoginSignup
1
1

More than 5 years have passed since last update.

Rubyの条件式

Posted at

通常のif文以外にも、一致しない場合のunlessや
一行で書く方法もある。

test_if.rb
# aとbが一致した場合、"Hello"が表示
if a == b then
   # 一致する場合
    puts "Hello"
else
   # 一致しない場合
   puts "World"
end

# aとbが一致した場合、"Hello"が表示
unless a == b then
   # 一致しない場合
   puts "World"
else
   # 一致する場合
   puts "Hello"
end


# aとbが一致した場合、"Hello"が表示
puts "Hello" if a == b
1
1
2

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
1