Skip to content
instance method

String#start_with?

(*::Regexp | ::string prefixes) -> bool
start_with?(*patterns) → true or false

Returns whether self starts with any of the given patterns.

For each argument, the pattern used is:

Returns true if any pattern matches the beginning, false otherwise:

Example
'hello'.start_with?('hell')               # => true
'hello'.start_with?(/H/i)                 # => true
'hello'.start_with?('heaven', 'hell')     # => true
'hello'.start_with?('heaven', 'paradise') # => false
'тест'.start_with?('т')                   # => true
'こんにちは'.start_with?('こ')              # => true

Related: see Querying.

See also #squeeze! #strip #squeeze #strip! also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0