Ruby 字符串 == 方法
==() 是Ruby中的一个字符串类方法,用于检查str是否==obj。
语法: str == obj
参数: 这里,str是给定的字符串,obj是要比较的对象。
返回: 根据两个字符串的相等程度, 返回 真或假。
例1 :
#ruby 2.3.1
# Ruby program to demonstrate
# the == method
# Taking a string and
# using the method
puts "Ruby" == "Ruby"
puts "Hello" == "Hell"
输出
true
false
例2 :
#ruby 2.3.1
# Ruby program to demonstrate
# the == method
# Taking a string and
# using the method
puts "ayucdef" == "ayucdefg"
puts "Ruby" == 77
输出
false
false
极客教程