What does “file.sync = true” do?

前端 未结 3 1025
谎友^
谎友^ 2021-01-17 09:44

I had a look at the docs but I can\'t seem to find the relevant part. Can anyone tell me what the call to sync is for in the following code?

fh          


        
3条回答
  •  终归单人心
    2021-01-17 10:12

    Tempfile inherits from IO. From the IO.sync docs:

      ios.sync    -> true or false
    
    ------------------------------------------------------------------------------
    
    Returns the current ``sync mode'' of ios. When sync mode is true, all
    output is immediately flushed to the underlying operating system and is not
    buffered by Ruby internally. See also IO#fsync.
    
      f = File.new("testfile")
      f.sync   #=> false
    

提交回复
热议问题