Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

String#end_with?

(*::string suffixes) -> bool
end_with?(*strings) → true or false

Returns whether self ends with any of the given strings.

Returns true if any given string matches the end, false otherwise:

Example
'hello'.end_with?('ello')               #=> true
'hello'.end_with?('heaven', 'ello')     #=> true
'hello'.end_with?('heaven', 'paradise') #=> false
'тест'.end_with?('т')                   # => true
'こんにちは'.end_with?('は')              # => true

Related: String#start_with?.

See also #encoding #eql? #encode! #force_encoding also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0