Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Ruby awesome_print to file?

I am trying to get awesome_print to output to a file rather than the console but I cant find out how to do this?

require "awesome_print"

mySymbolizedHash = {'blah' => 'blabbbb', 'this' => 'that'}

This will write to console, I need to write the formatted output to file.

If I write the hash directly to a file, its not formatted they way I want.

ap mySymbolizedHash  
like image 476
Mark Babcock Avatar asked Feb 13 '15 23:02

Mark Babcock


1 Answers

File.open('some_file', 'w') do |f|
  f.write mySymbolizedHash.awesome_inspect
end

awesome_inspect seems undocumented, but ai seems to be an alias, and that's used all over the place.

You could redirect STDOUT to a file, as shown here: http://stackoverflow.com/questions/1470344/outputting-stdout-to-a-file-and-back-again awesome_print doesn't seem to return the value, so no assigning it to a variable :(
like image 99
Satya Avatar answered Sep 29 '22 07:09

Satya