Open In App

Ruby | String end_with? Method

Improve
Improve
Like Article
Like
Save
Share
Report

end_with? is a String class method in Ruby which is used to check if the specified string ends with one of the suffixes given or not.

Syntax: str.end_with?

Parameters: Here, str is the given string.

Returns: true if it matches otherwise return false.

Example 1:




# Ruby program to demonstrate 
# the end_with? method 
       
# Taking a string and 
# using the method
puts "Ruby".end_with?("by"
puts "String".end_with?("ab"


Output:

true
false

Example 2:




# Ruby program to demonstrate 
# the end_with? method 
       
# Taking a string and 
# using the method
# returns true if one of
# the +suffixes+ matches.
puts "Sample".end_with?("ple", "sam")
puts "Program".end_with?("gr", "pro"


Output:

true
false

Last Updated : 12 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads