漂亮打印到红宝石文件

问题描述:

我正在尝试将哈希值漂亮地打印到文件中.

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

我尝试了unix重定向[向其逐步添加了不同的标志]:

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

`echo #{pp  mymap} | tee summary.out 2>&1`

和文件IO

 my_file = File.new(@dir_+"/myfile.out",'w+')          
 my_file.puts `#{pp get_submap_from_final(all_mapping_file,final_map)}`

它总是打印到控制台并且不写入文件.

It always prints to console and doesnt write to a file.

还必须有一种更简单的方法来在ruby中一行写入文件吗?而不是执行File.new然后写入文件?

Also there has to be an easier way to write to file in one line in ruby ? instead of doing File.new and then writing to a file ?

require 'pp'

File.open("test.txt","w") do |f|
  PP.pp(self,f)
end