user2015453 user2015453 - 1 year ago 89
Ruby Question

Putting the results of pp (or anything outputted to console) into a string

We know

require 'pp'
a=["value1", "value2", "value3"]
pp a

pretty prints the array as an output to the console. How do I get that pretty output into a string (a string containing the newlines that makes things pretty, etc.)?

...purpose being to return that pretty string from a method.

Answer Source

pretty_inspect also comes along when you require 'pp' - See:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download