Open In App

Ruby| String Clear Method

Improve
Improve
Like Article
Like
Save
Share
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:




Last Updated : 13 Dec, 2019
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads