How to check if two strings are equal in Ruby
Overview
In this shot, we will check if two strings are equal with the eql?() method. Two strings are equal if they both have the same length and content with the same case.
Syntax
str.eql?(other_str)
Parameters
other_str: The string we compare with the string instance.
Return value
The value returned is a Boolean. It returns the true if the strings are equal. Otherwise, false is returned.
Example
# compare stringsputs "one".eql?("one"); # trueputs "two".eql?("two"); # trueputs "three".eql?("three"); # trueputs "FIVE".eql?("five"); # falseputs "six".eql?("Six"); # false
Explanation
All the first three string comparisons return true because they are equal. The rest are not equal because they are not of the same case. That is why they will return false.