OneBite.Dev - Coding blog in a bite size

compare two strings in Ruby

Code snippet on how to compare two strings in Ruby

a = "hello"
b = "hello"

if a == b
  puts "The two strings are equal!"
else
  puts "The two strings are not equal!"
end

This code compares two strings, a and b, to see if they are the same. It starts by declaring the two strings, a and b. Then, it checks if a is equal to b using the == operator. If they are equal, it will print out “The two strings are equal!” to the console. If a is not equal to b, then the code will print out “The two strings are not equal!” to the console.

ruby