Skip to content
Related Articles
Open in App
Not now

Related Articles

Ruby| String Clear Method

Improve Article
Save Article
  • Last Updated : 13 Dec, 2019
Improve Article
Save Article

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

Output:



Example 2:




# Ruby program to demonstrate 
# the clear method 
       
# Taking a string and 
# using the method 
puts "".clear
puts "Ruby".clear

Output:



My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!