结合两句话

时间:2015-04-18 20:07:38

标签: ruby

我有一些问题survey.rb

puts "Let's take a survey."
puts "Who is your mom?"
mom = gets.chomp
puts "Hello, I am "
print mom
print"."

当我运行它时,结果是:

Let's take a survey.
Who is your mom?
EAD (for example)
Hello, I am
EAD.

如何将'Hello, I am''EAD'合并在一起?

2 个答案:

答案 0 :(得分:2)

两个选项。您可以使用print:

替换puts "hello, I am "
print "Hello, I am "
print mom
puts "."

或者使用字符串插值:

puts "Hello, I am #{mom}."

答案 1 :(得分:2)

您是否曾尝试使用

等2种打印方式进行此操作
     print 'Hello, I am'
     print mom
     puts '.'