How to get Ruby awesome_print file?

I'm trying to get awesome_print for output to a file, not to the console, but I can’t find out how to do this?

 require "awesome_print" mySymbolizedHash = {'blah' => 'blabbbb', 'this' => 'that'} 

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

If I write a hash directly to a file, it is not formatted the way I want.

 ap mySymbolizedHash 
+5
source share
1 answer
 File.open('some_file', 'w') do |f| f.write mySymbolizedHash.awesome_inspect end 

awesome_inspect seems to be undocumented, but ai appears to be an alias and is used everywhere.

You can redirect STDOUT to a file as shown here: http://stackoverflow.com/questions/1470344/outputting-stdout-to-a-file-and-back-again awesome_print does not seem to return a value, so without assigning it variable :( affairs>
+9
source

Source: https://habr.com/ru/post/1213365/


All Articles