Open In App

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

Output:



Example 2:




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

Output:



Article Tags :