pretty print to a file in ruby

后端 未结 7 779
甜味超标
甜味超标 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条回答
  •  -上瘾入骨i
    2021-02-07 00:17

    The use of backticks here is perplexing since those are used for executing shell commands.

    What you probably mean is:

    File.open(@dir_+"/myfile.out",'w+') do |f|
      f.write(pp(get_submap_from_final(all_mapping_file,final_map)))
    end
    

    The pp method always writes to the console so you might see it and still have it written.

提交回复
热议问题