Skip to content
Related Articles

Related Articles

Ruby | String delete_suffix Method
  • Last Updated : 13 Dec, 2019

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.

Syntax: str.delete_suffix

Parameters: Here, str is the given string.

Returns: A copy of the given string with trailing suffix deleted.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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


Output:

Ru
Clas

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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


Output:

Sample
Inp
My Personal Notes arrow_drop_up
Recommended Articles
Page :