Ruby String Comparison



String comparison needs another section to understand:

There are 2 equal comparison conditionals for ruby strings as follows:

a. == returns true if two objects are strings.
b. eql? returns true if two strings are equal in length and content.

Ruby String Comparison

#!/usr/bin/ruby
#File: rubystringcomparisontest.rb
 
newstring = String.new("string comparison test")
newstring = newstring.downcase
 
newstring1 = String.new("string comparison test 2")
 
 
puts "#{newstring}"
puts "#{newstring1}"
puts newstring.eql?(newstring1)
puts (newstring == newstring1)

Output would be:

string comparison test
string comparison test 2
false
true