DEV Community

Lam
Lam

Posted on

2 3

Pry Cheat Sheet

Reference

# In your code:
binding.remote_pry

# In the shell:
bundle exec pry-remote
Enter fullscreen mode Exit fullscreen mode

pry-rescue

Add the pry-rescue gem.

Pry::rescue {
  # raise exceptions here
}
Enter fullscreen mode Exit fullscreen mode

Or run:

bundle exec rescue rspec
Enter fullscreen mode Exit fullscreen mode

Additional commands:

pry(main)> cd-cause
pry(main)> try-again
Enter fullscreen mode Exit fullscreen mode

hirb

Add the hirb gem.

> table User.all
> view User.all
> view User.all, fields: %w[id name email]
Enter fullscreen mode Exit fullscreen mode

Shell integration

shell-mode adds dir to the prompt.

pry(main)> shell-mode
pry(main):/home/x $
Enter fullscreen mode Exit fullscreen mode

Commands with . are shell commands.

pry(main)> .cat hello.txt
Enter fullscreen mode Exit fullscreen mode




[Rails] ls


> ls         # All

> ls -m # Methods
> ls -M # Instance methods

> ls -g # Globals
> ls -l # Local vars
> ls -c # Constants

> ls -i # Instance vars

> ls -G xx # Grey by regex

Enter fullscreen mode Exit fullscreen mode




[Rails] Rails


> show-models
> show-routes
> show-middleware
Enter fullscreen mode Exit fullscreen mode




[Rails] Rails console

Also consider pry-rails.

$ pry -r ./config/environment
Enter fullscreen mode Exit fullscreen mode




Misc commands


> hist          # History
> wtf? # Trace of recent exception
Enter fullscreen mode Exit fullscreen mode




Gems


> gem-cd foo      # Switch to gem's dir
> gem-install foo
> gem-list
Enter fullscreen mode Exit fullscreen mode




Reference

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay