Ruby| String Clear Method
clear is a String class method in Ruby which is used to make the string empty.
Syntax: str.clear
Parameters: Here, str is the given string.
Return : An empty string.
Example 1:
# Ruby program to demonstrate # the clear method # Taking a string and # using the method puts "String".clear puts "Class".clear |
chevron_right
filter_none
Output:
Example 2:
# Ruby program to demonstrate # the clear method # Taking a string and # using the method puts "".clear puts "Ruby".clear |
chevron_right
filter_none
Output:
Recommended Posts:
- Ruby | clear() function
- Ruby | Set clear() function
- Ruby | Array clear() operation
- Ruby | StringScanner clear function
- Ruby | SizedQueue clear() function
- Ruby | Hash clear() function
- Ruby | Queue clear() function
- Ruby | String eql? Method
- Ruby | String == method
- Ruby | String hex Method
- Ruby | String === Method
- Ruby | String <=> Method
- Ruby | String * Method
- Ruby | String chr Method
- Ruby | String + 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.



