Open In App
Related Articles

Ruby | String delete_suffix! Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

delete_suffix! is a String class method in Ruby which is used to return a copy of the given string with trailing suffix deleted or nil if no change was made.

Syntax:str.delete_suffix! Parameters: Here, str is the given string. Returns: A copy of the given string with trailing suffix deleted or nil if no change was made.

Example 1: 

Ruby

# Ruby program to demonstrate
# the delete_suffix! method
      
# Taking a string and
# using the method
puts "Ruby".delete_suffix!("by")
puts "Class".delete_suffix!("s")

                    

Output:

Ru
Clas

Example 2: 

Ruby

# Ruby program to demonstrate
# the delete_suffix! method
      
# Taking a string and
# using the method
puts "Sample".delete_suffix!("pl")
puts "Input".delete_suffix!("ut")

                    

Output:

Inp

Last Updated : 04 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads