To check if an array is not empty in Ruby, you can use the empty?
method to check if the array has any elements. The empty?
method returns true
if the array is empty and false
if it has any elements.
Here's an example:
main.rb90 chars8 lines
This example defines an empty array array
and then uses a conditional statement to check if it's not empty using the !
(not) operator. If the array is not empty, the program prints "Array is not empty". Otherwise, it prints "Array is empty".
gistlibby LogSnag