Syntax

Ruby Unless Syntax

In Ruby, unless: runs code when a condition is false — puts "empty" unless list.any?

Quick Answer

Syntax
puts "empty" unless list.any?
RubySyntax

Unless

Code example
puts "empty" unless list.any?

Runs code when a condition is false.

Learn More

How to unless in Ruby

  1. Open your Ruby file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Ruby Unless Syntax

Use puts "empty" unless list.any?.

Related Syntax References

Frequently asked questions

What is the Ruby syntax for unless?

Use this pattern: puts "empty" unless list.any?

Can I copy this Ruby code example?

Yes. Use Copy code and adapt the example to your program.

Is this Ruby syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify