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
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
22