字符串以。开头

要查找字符串是否以模式开头,start_with? 方法会派上用场

str = "zebras are cool"
str.start_with?("zebras")      => true

你还可以使用 index 检查图案的位置

str = "zebras are cool"
str.index("zebras").zero?      => true