assert arg (anything)
Raises an exception if the argument is either nil or false.
Introduced in v2.8
assert true assert 1 assert "foo" assert false
# Simple assertions # As true is neither nil or false, this assertion passes # Similarly, 1 passes # As do string # This will raise an exception
assert false, "oops"
# Communicating error messages # This will raise an exception containing the message "oops"
assert (1 + 1) == 2 assert [:a, :b, :c].size == 3
# More interesting assertions # Ensure that arithmetic is sane! # ensure lists can be correctly counted