红宝石 |字符串 eql?方法
情商?是 Ruby 中的 String 类方法,用于检查字符串是否相等,如果它们具有相同的长度和内容。
Syntax: str.eql?(Other_str)
Parameters: Here, str and other_str are the strings.
Returns: True or false basis on the equality.
示例 1:
# Ruby program to demonstrate
# the eql? method
# Taking a string and
# using the method
puts "Sample".eql?("Sample")
# case sensitive
puts "Program".eql?("program")
输出:
true
false
示例 2:
# Ruby program to demonstrate
# the eql? method
# Taking a string and
# using the method
puts "Ruby".eql?("ruby")
# case sensitive
puts "String".eql?("String")
输出:
false
true