How to use “gets” and “gets.chomp” in Ruby

前端 未结 6 1119
一整个雨季
一整个雨季 2020-12-01 06:29

I learned that gets creates a new line and asks the user to input something, and gets.chomp does the same thing except that it does not create a ne

6条回答
  •  时光说笑
    2020-12-01 06:45

    For example:

    x = gets
    y = gets
    puts x+y
    

    and

    x = gets.chomp
    y = gets.chomp
    puts x+y
    

    Now run the two examples separately and see the difference.

提交回复
热议问题