红宝石|字符串清除方法
clear是 Ruby 中的 String 类方法,用于使字符串为空。
Syntax: str.clear
Parameters: Here, str is the given string.
Return : An empty string.
示例 1:
# Ruby program to demonstrate
# the clear method
# Taking a string and
# using the method
puts "String".clear
puts "Class".clear
输出:
示例 2:
# Ruby program to demonstrate
# the clear method
# Taking a string and
# using the method
puts "".clear
puts "Ruby".clear
输出: