Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/selfup/pryman
A way to snapshot and save a pry session.
https://github.com/selfup/pryman
Last synced: about 1 month ago
JSON representation
A way to snapshot and save a pry session.
- Host: GitHub
- URL: https://github.com/selfup/pryman
- Owner: selfup
- Created: 2015-07-03T17:02:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-06T07:25:21.000Z (about 9 years ago)
- Last Synced: 2024-10-20T07:36:04.013Z (2 months ago)
- Language: Ruby
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pryman
A way to save a snapshot of a pry session.# How it works
Paste this into your **".pryrc"** file:
```ruby
Pry::Commands.block_command "batman", "Save the session" do |filename|
filename ||= "batman.rb"
filename = Pathname.new filenamewhile File.exist? filename
no_ext = filename.basename.sub_ext('').to_s
counter = no_ext[/\d+$/].to_i.next
incremented = Pathname.new(no_ext.sub /\d*$/, counter.to_s)
filename = filename.dirname + incremented.sub_ext(filename.extname)
endinout = _pry_.input_array.to_a.zip(_pry_.output_array.to_a)
body = inout.map { |input, output|
inspected_output = output.inspect.gsub(/^/, ' # ')
"#{input}#{inspected_output}"
}.join("\n")
File.write(filename, body)
end
```**1)** Say you are learning a new concept and testing it out in pry, but you want to save it to a **".rb"** file.
**2)** Now you just type in (while in pry):
$ batman
It will write a file called **"batman.rb""**.
**3)** If you run **"batman"** again, it will add **"1"** to **"batman"**.
So **"batman1.rb"**.
**4)** If you call:
$ batman lol.rb
It will now make a file called **"lol.rb"** instead of "batman.rb"
**5)** It will save the new file to your CURRENT WORKING directory.
----------------------------------------------------------------------------------------
#### Many Thanks to Josh Cheek from Turing for helping me out.
Check out his work: @JoshCheek