LoginSignup
2
2

More than 5 years have passed since last update.

Ruby unless/case

Posted at
unless 条件 then
 文
end

case 比較したいオブジェクト
 when 値1 then
  文1
 when 値2 
  文2
 when 値3
  文3
 else
  文4
 end

case.rb
tags = [ "A", "IMG", "PRE"]
tags.each do |tagname|
 case tagname
when "P", "A", "I", "B", "BLOCKQUOTE"
 puts "#{tagname} has child"
when "IMG", "BR"
puts "#{tagname} has no child"
else
puts "#{tagname} can not be used"
 end
end

> ruby case.rb
A has child, IMG has no child, PRE can not be used
2
2
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
2
2