Why doesn't puts() print in a single line?

后端 未结 3 1329
生来不讨喜
生来不讨喜 2021-01-22 03:10

This is a piece of code:

def add(a, b) 
  a + b;
end

print \"Tell number 1 : \"
number1 = gets.to_f

print \"and number 2 : \"
number2 = gets.to_f

puts \"#{num         


        
3条回答
  •  无人及你
    2021-01-22 04:08

    Puts adds a newline to the end of the output. Print does not. Try print.

    http://ruby-doc.org/core-2.0/IO.html#method-i-puts

    You might also want to replace gets with gets.chomp.

    puts "After entering something, you can see the the 'New Line': "
    a = gets
    print a
    
    puts "After entering something, you can't see the the 'New Line': "
    a = gets.chomp
    print a
    

提交回复
热议问题