Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Symbol#start_with?

sym.start_with?([prefixes]+) → true or false

Returns true if sym starts with one of the prefixes given. Each of the prefixes should be a String or a Regexp.

Example
:hello.start_with?("hell")               #=> true
:hello.start_with?(/H/i)                 #=> true

# returns true if one of the prefixes matches.
:hello.start_with?("heaven", "hell")     #=> true
:hello.start_with?("heaven", "paradise") #=> false
See also #slice #succ #size #swapcase also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1