Ruby | String chop Method
chop is a String class method in Ruby which is used to return a new String with the last character removed. Both characters are removed if the string ends with \r\n, b. Applying chop to an empty string returns an empty string.
Syntax:str.chop
Parameters: Here, str is the given string.
Returns: A new string having no record seperator.
Example 1:
# Ruby program to demonstrate # the chop method # Taking a string and # using the method puts "Ruby".chop puts "Ruby\r\n".chop |
chevron_right
filter_none
Output:
Rub Ruby
Example 2:
# Ruby program to demonstrate # the chop method # Taking a string and # using the method puts "String\r\n\r\r\n".chop # Removing two characters puts "Method".chop.chop |
chevron_right
filter_none
Output:
String Meth
Recommended Posts:
- Ruby | String chop! Method
- Ruby | String hex Method
- 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 * Method
- Ruby | String capitalize() Method
- Ruby | String each_codepoint Method
- Ruby | String getbyte Method
- Ruby | String grapheme_clusters 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.



