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
Given the mymap
from the question, you can use the "show_data" gem, which provides two methods: show_data
and format_data
. The latter produces a "pretty-printed" string of its argument which can then be fed to any output method.
require 'show_data'
$stderr.puts format_data(mymap)
For example:
myhash = { 'owners' => 21050, 'users' => 16877, 'portfolios' => 583,
'properylists' => 0, 'properties' => 29504, 'units' => 62688,
'tenants' => 85856 }
$stderr.puts format_data(myhash)
on STDERR:
{ 'owners' => 21050,
'users' => 16877,
'portfolios' => 583,
'properylists' => 0,
'properties' => 29504,
'units' => 62688,
'tenants' => 85856
}