String#end_with?
str.end_with?(*suffixes) -> true or false Returns:
boolean · Updated March 13, 2026 · String Methods strings pattern-matching checking
The end_with? method checks whether a string ends with one or more specified suffixes. It returns true if the string ends with any of the given substrings, otherwise false. This method is case-sensitive.
Syntax
str.end_with?(*suffixes)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
*suffixes | String | — | One or more substrings to check as potential endings |
Examples
Basic usage
"hello".end_with?("o")
# => true
"hello".end_with?("lo")
# => true
"hello".end_with?("ll")
# => false
Checking multiple suffixes
"document.txt".end_with?(".txt", ".pdf", ".doc")
# => true
"image.png".end_with?(".txt", ".pdf")
# => false
Case sensitivity
"Ruby".end_with?("ruby")
# => false
"Ruby".end_with?("Ruby")
# => true
Common Patterns
File extension checking
def text_file?(filename)
filename.end_with?(".txt", ".md", ".rtf")
end
text_file?("readme.md") # => true
text_file?("script.rb") # => false
URL path validation
def html_page?(path)
path.end_with?(".html", ".htm")
end
html_page?("/about.html") # => true
html_page?("/about") # => false