Skip to content
Related Articles

Related Articles

Ruby | String end_with? Method

View Discussion
Improve Article
Save Article
  • Last Updated : 12 Dec, 2019
View Discussion
Improve Article
Save Article

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!