我总是这样做来测试Ruby中的字符串相等性:
if mystring.eql?(yourstring)
puts "same"
else
puts "different"
end
在不测试对象相等性的情况下,这是正确的方法吗?
我正在寻找基于内容测试字符串的最简洁的方法.
With the parentheses and question mark, this seems a little clunky.
我总是这样做来测试Ruby中的字符串相等性:
if mystring.eql?(yourstring)
puts "same"
else
puts "different"
end
在不测试对象相等性的情况下,这是正确的方法吗?
我正在寻找基于内容测试字符串的最简洁的方法.
With the parentheses and question mark, this seems a little clunky.
根据http://www.techotopia.com/index.php/Ruby_String_Concatenation_and_Comparison
要么
mystring == yourstring
或
mystring.eql? yourstring
它们是等价的.