What's the difference between Ruby's puts and write methods?

前端 未结 2 1932
执念已碎
执念已碎 2021-02-18 18:32

What\'s the difference between...

File.open(\'abc\', \'w\') { |f| f.puts \'abcde\' }

...and...

File.open(\'abc\', \'w\') { |f|          


        
2条回答
  •  梦谈多话
    2021-02-18 19:02

    puts appends a newline, write does not. Technically, puts appends the record separator (which is usually a newline) to the output if it doesn't have one at the end. write outputs only what it is given.

提交回复
热议问题