其区别主要体现在输出时
how old are you?11
how muchdo you weight?333
例如 :
print “how old are you?”
age=gets.chomp()
print “how tall are you?”
height=gets.chomp()
print “how much do you weight?”
weight=gets
puts “so ,you’re #{age} old,#{height} tall and#{weight} heavy.” #(这一整句都是在一行的)
>ruby test.rb
how tall are you?22
so ,you’re 11 old,22 tall and333
heavy.
即 gets中包含了”\n” 而 gets.chomp 中不包括”\n”
此文章通过 python 爬虫创建,原文是自己的csdn 地址: ruby中gets 和 gets.chomp 区别