Open In App

Ruby | String end_with? Method

Last Updated : 12 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
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
# 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
# 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

Next Article

Similar Reads