In Ruby, you can check if an array is empty using the empty?
method. This method returns true
if the array is empty, and false
otherwise.
Here's an example:
main.rb89 chars8 lines
Alternatively, you can check the size of the array using the length
method. If the length is 0, then the array is empty.
Here's an example using the length
method:
main.rb94 chars8 lines
Both methods will give you the same result.
Remember to replace array
with the actual array variable you want to check.
gistlibby LogSnag