pretty print to a file in ruby

后端 未结 7 782
甜味超标
甜味超标 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:22

    require 'pp'
    
    class File
      def pp(*objs)
        objs.each {|obj|
          PP.pp(obj, self)
        }
        objs.size <= 1 ? objs.first : objs
      end
    end
    
    File.open('output','w') do |file|
      file.pp mymap
    end
    

提交回复
热议问题