简体   繁体   English

看跌期权和MESSAGE之间的区别?

[英]Difference between puts and MESSAGE?

What is the difference between using MESSAGE and tags for the last string? 对最后一个字符串使用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

What you see is something called here-docs . 您看到的是一个叫做here-docs的东西。 It's a convenient way to have multiline strings without having to escape quotes. 这是拥有多行字符串而不必转义引号的便捷方法。 Besides this, they are just regular strings. 除此之外,它们只是常规字符串。

Some editors may offer additional features. 一些编辑器可能会提供其他功能。 See my other answer about this. 看到对此的其他答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM