字串以。開頭

要查詢字串是否以模式開頭,start_with? 方法會派上用場

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

你還可以使用 index 檢查圖案的位置

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