看跌期权与MESSAGE的区别?

时间:2012-06-16 22:09:30

标签: ruby

使用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

1 个答案:

答案 0 :(得分:3)

你看到的是here-docs。这是一种方便的方式来获得多行字符串而不必转义引号。除此之外,它们只是常规字符串。

某些编辑可能会提供其他功能。有关此内容,请参阅my other answer