Unless
unless,作为一个语句或修饰符,和if恰好相反:当且仅当与其关联的表达式的值为false或nil,它才会执行相应的代码。
unless condition
code
end
unless condition
code
else
code
end
s=unless o.nil?
o.to_s
end
s=unless o.nil? then o.to_s end
unless x==0
puts "x is not 0"
else
unless y==0
puts "y is not 0"
else
unless z==0
puts "z is not 0"
else
puts "all are 0"
end
end
end
2011-4-17 16:54 danny
unless,作为一个语句或修饰符,和if恰好相反:当且仅当与其关联的表达式的值为false或nil,它才会执行相应的代码。
unless condition
code
end
unless condition
code
else
code
end
s=unless o.nil?
o.to_s
end
s=unless o.nil? then o.to_s end
unless x==0
puts "x is not 0"
else
unless y==0
puts "y is not 0"
else
unless z==0
puts "z is not 0"
else
puts "all are 0"
end
end
end
2011-4-17 16:54 danny