OneBite.Dev - Coding blog in a bite size

check if a string is empty in Ruby

Code snippet on how to check if a string is empty in Ruby

if string == ""
  puts "String is empty"
else 
  puts "String is not empty"
end

This code snippet checks if a string, represented by the variable “string”, is empty or not. Firstly, the code performs a comparison between the variable “string” and an empty string. If they are equal, then the code outputs “String is empty”. Otherwise, it outputs “String is not empty”. This code is a simple and efficient way of determining whether a String is empty or not.

ruby