pretty print to a file in ruby

后端 未结 7 798
甜味超标
甜味超标 2021-02-07 00:11

I am trying to pretty print a hash to a file.

I tried unix redirects [added different flags to it incrementally] :

`echo #{pp  mymap} | tee summary.out          


        
7条回答
  •  不思量自难忘°
    2021-02-07 00:40

    What about (not using pp directly):

    File.open("myfile.out","w+") do |f|
      f.puts mymap.inspect
    end
    

    Or even redirect stdout for the file

    file = File.open("myfile.out", "w+)
    
    old_stdout = STDOUT
    
    $stdout = STDOUT = file
    
    pp get_submap_from_final(all_mapping_file,final_map)
    
    $stdout = STDOUT = old_stdout
    

提交回复
热议问题