Ruby 字符串 clear方法 clear 是Ruby中的一个字符串类方法,用于使字符串变空。 语法: str.clear 参数: 这里,str是给定的字符串。 返回: 一个空字符串。 例子 1 : # Ruby program to demonstrate # the clear method # Taking a string and # using the method puts "String".clear puts "Class".clearRubyCopy 例2 : # Ruby program to demonstrate # the clear method # Taking a string and # using the method puts "".clear puts "Ruby".clearRubyCopy