红宝石 |字符串检查方法
inspect是 Ruby 中的 String 类方法,用于返回给定字符串的可打印版本,用引号括起来,特殊字符转义。
Syntax: str.inspect
Parameters:
Returns: Here, str is the given string.
示例 1:
# Ruby program to demonstrate
# the inspect method
# Taking a string and
# using the method
puts "Sample".inspect
puts "Articles".inspect
输出:
"Sample"
"Articles"
示例 2:
# Ruby program to demonstrate
# the inspect method
# Taking a string and
# using the method
puts "Ru \n y".inspect
puts "Ar\b\\bcles".inspect
输出:
"Ru \n y"
"Ar\b\\bcles"