「Ruby」unless修飾子のサンプル

構文
code unless conditional
サンプルコード

#!/usr/bin/ruby
# -*- coding: UTF-8 -*-

$var =  1
print "AA11 -- this line output message\n" if $var
print "BB22 -- this line is not output message\n" unless $var
 
$var = false
print "CC33 -- this line is output message\n" unless $var

実行結果
>ruby test.rb
AA11 — this line output message
CC33 — this line is output message

Ruby

Posted by arkgame