0

MESSAGE最后一个字符串的使用和标签有什么区别?

user = ARGV.first
prompt = '>  '

puts "Hi #{user}, im the #{$0} script."
puts "I'd like to ask you a few questions."
puts "Do you like me #{user}?"
print prompt
likes = STDIN.gets.chomp()

puts "Where do you live #{user}?"
print prompt
lives = STDIN.gets.chomp()

puts "What kind of computer do u have?"
print prompt
computer = STDIN.gets.chomp()

puts <<MESSAGE
"Alright, so you said #{likes} about liking me. You live in #{lives}. Not sure where it is.
And you have a #{computer} computer, which is nice." 
MESSAGE
4

1 回答 1

3

你看到的是一个叫做here-docs的东西。这是一种无需转义引号即可拥有多行字符串的便捷方式。除此之外,它们只是常规字符串。

一些编辑器可能会提供额外的功能。请参阅我的其他答案

于 2012-06-16T22:12:26.677 回答