Does Ruby have a string.startswith(“abc”) built in method?

后端 未结 4 1159
轻奢々
轻奢々 2020-12-23 12:41

Does Ruby have a some_string.starts_with(\"abc\") method that\'s built in?

4条回答
  •  滥情空心
    2020-12-23 13:17

    If this is for a non-Rails project, I'd use String#index:

    "foobar".index("foo") == 0  # => true
    

提交回复
热议问题