String starts with

suggest change

To check whether a string starts with a prefix, use start_with?.

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

index returns the position of a substring, so zero? is true when that position is the start. If the substring is missing, index returns nil and nil.zero? raises NoMethodError.

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents