String

# 定义字符串 String
h1 = "2.00米"
h2 = "8.00米"
# 把字符串前导字符解释为 Numeric 结果
amount1 = h1.to_i(base=10)
@amount2 = h2.to_i(base=10)
# 定义字符串嵌入一般变量
height1 = "#{(amount1 + @amount2) * 1000}mm"
# 定义字符串嵌入实例变量
height2 = "#@amount2 m"


"sample".length
6
"sample".length + "text"
# TypeError: String can't be coerced into Integer
"sample".length.to_s + "text"
6text
© AWhouse