Ruby | String end_with? Method
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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.