📜  红宝石 |字符串 + 方法

📅  最后修改于: 2022-05-13 01:55:16.140000             🧑  作者: Mango

红宝石 |字符串 + 方法

+()是 Ruby 中的 String 类方法,用于返回一个新字符串,该字符串包含与给定字符串。

示例 1:

#ruby 2.3.1 
     
# Ruby program to demonstrate
# the + method
     
# Taking a string and
# using the method
puts "Hello " + "Geeks!"
puts "Ruby " + "String"

输出:

Hello Geeks!
Ruby String

示例 2:

#ruby 2.3.1 
     
# Ruby program to demonstrate
# the + method
     
# Taking a string and
# using the method
puts "Hey " + "Champ"
puts "Kirti " + "Mangal"

输出:

Hey Champ
Kirti Mangal