- 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."
运行如下
所以区别在于 input 包不包括 \n gets包括 gets.chomp不包括
- >ruby test11.rb
- how old are you?10
- how tall are you12
- how much do you weight?111
- so ,you're 10 old,12 tall and111
- heavy.