How to dump Pry output to a file or Vim?

I have a Rails application and I'm trying to export data, but directly through Pry , because I only need to do this once.

Is this possible with Pry? I looked through the documentation, but it doesn't seem like there is an easy way to reset console data anywhere.

+4
source share
2 answers

I have a hash with nested hashes / objects that I need to send to a third party to work with the API. They need a data dump so that they can configure the receiving part of my call. I'm going to do it in Ruby right now, but it would be wiser to dump data through PRY rather than edit my ruby ​​object to dump the data that I need only once.

If you can start the server from the local command line or SSH to the host and start the instance there, you can use Pry to do this. Basically you need to add these lines to your code in the appropriate place:

require 'pry-debugger'; binding.pry

which will stop your code and put you at the Pry prompt. At this point, you can enter something like:

require 'json'
File.write('test.data', hash.to_json)

Pry.debugger Pry Rails, .

+12

( output.txt):

x = 'something funky'
.echo '#{x}' > output.txt

. .

+1

All Articles