Open In App

Ruby| String Clear Method

Last Updated : 13 Dec, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report

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:





Next Article

Similar Reads