Jonah
Jonah

Reputation: 16242

Edit a file from pry but affect only the in memory version

The pry edit Class#method command is a nice feature that allows you to jump directly into the source code of any loaded file, edit it, and jump back into pry with the changes loaded when you quit.

But sometimes I don't want to permanently edit the actual file on the file system. Instead, I want everything to work the way edit command does currently, but I want the actual file system file to revert to what it was prior to my editing it, after the edited version is loaded into pry.

For example, I might want to patch some gem to see how it works, or play around with it, but leave everything intact after I'm done playing. Is there a good way to accomplish this in pry?

Upvotes: 1

Views: 417

Answers (1)

Atri
Atri

Reputation: 5831

Use the -p switch with edit. This will not change the file, only an in-memory version of it.

Something like:

pry(main)> edit -p Class#method

More info in the doc.

Upvotes: 2

Related Questions