String starts with
suggest changeTo 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
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents