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.
str.eql?(other_str)
other_str
: The string we compare with the string instance.
The value returned is a Boolean. It returns the true
if the strings are equal. Otherwise, false
is returned.
# compare stringsputs "one".eql?("one"); # trueputs "two".eql?("two"); # trueputs "three".eql?("three"); # trueputs "FIVE".eql?("five"); # falseputs "six".eql?("Six"); # false
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
.