Ruby | String delete_suffix! Method
delete_suffix! is a String class method in Ruby which is used to return a 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 program to demonstrate # the delete_suffix! method # Taking a string and # using the method puts "Ruby".delete_suffix!("by") puts "Class".delete_suffix!("s") |
chevron_right
filter_none
Output:
Ru Clas
Example 2:
# 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") |
chevron_right
filter_none
Output:
Inp
Recommended Posts:
- Ruby | String * Method
- Ruby | String + Method
- Ruby | String == method
- Ruby | String chr Method
- Ruby | String === Method
- Ruby | String eql? Method
- Ruby | String =~ Method
- Ruby | String << Method
- Ruby | String hex Method
- Ruby | String <=> Method
- Ruby | String center() method
- Ruby | String hash method
- Ruby | String gsub! Method
- Ruby | String chomp! Method
- Ruby | String chop Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



