PRY(1)

πŸ’… PRY β€” the pry(1) manual, bestie edition ✨

okay so. you opened the manual for PRY, and honestly? you're about to have a great time. this is the page for the PRY repl, and no cap, it's a whole vibe. 🌸


🌈 NAME

PRY β€” A Reference to the PRY repl.

like. that's it. that's the name. iconic. πŸ‘‘


πŸŽ€ Synopsis

pry [--version] [--exec] [--no-pager] [--no-history] [--no-color] [-f]
[--no-plugins] [--installed-plugins] [--simple-prompt] [--require file]
[-I] [--context] [--help]

✨ DESCRIPTION

so basically πŸ’– Pry is a powerful alternative to the standard IRB shell for Ruby. it was written from scratch β€” from scratch, bestie, no hand-me-downs β€” specifically to provide a number of advanced features. it's giving main character energy in a repl. periodt.


🌐 HOMEPAGE

http://pry.github.com/


πŸ’… OPTIONS

here's the full menu, no skipping, we read every single one 🫢

  • -v, --version β€” Prints the version of Pry. quick lil flex check. ✨
  • -e, --exec β€” Executes argument in context before the session starts. like a lil warm-up stretch before the main performance. πŸ”₯
  • --no-pager β€” Disable pager for long output. so when something dumps a novel at you, it just... dumps it. all at once. raw. πŸ’€
  • --no-history β€” Disable history loading. your past commands stay in the past, no receipts. πŸ™ˆ
  • --no-color β€” Disable syntax highlighting for session. monochrome mode. we mourn. πŸ₯²
  • -f β€” Prevent loading of ~/.pryrc for session. fresh start, blank slate, new era. πŸ¦‹
  • --no-plugins β€” Suppress loading of plugins. no extras, just vibes. ✨
  • --installed-plugins β€” List installed plugins. show me the roster πŸ‘€
  • --simple-prompt β€” Enable simple prompt mode (eg, >>). minimalist. understated. lowkey chic. πŸ’œ
  • -r, --require β€” Require a ruby script at startup.
  • -I β€” Add a path to the $LOAD_PATH
  • -c, --context β€” Start the session in the specified context. Equivalent to context.pry in a session.

πŸ“ FILES

  • ~/.pryrc β€” Personal pry initialization

that's the one. your little home file. your pry bedroom decor. πŸŽ€


🌸 EXAMPLES

πŸ’– Basic Usage

$ pry
[1] pry(main)>4 + 5
=> 9
[2] pry(main)> def hello_world
[2] pry(main)*   puts "Hello, World!"
[2] pry(main)* end
=> nil
[3] pry(main)> hello_world
Hello, World!
=> nil

look at her go. arithmetic, a method definition, and a little Hello, World! β€” she ate and left no crumbs. 🌈


🐚 Command Line Interaction

Prefix any command you want your shell to execute with a period and pry will return the results from your shell.

[1] pry(main)> .date
Fri Nov 11 09:52:07 EST 2011

yes bestie, a literal . and then boom, your shell does the thing and hands you back the output. πŸ’«

On the command line enter shell-mode to incorporate the current working directory into the Pry prompt.

pry(main)> shell-mode
pry main:/Users/john/ruby/projects/pry $ .cd ..
pry main:/Users/john/ruby/projects $ .cd ~
pry main:/Users/john $ .pwd
/Users/john
pry main:/Users/john $ shell-mode
pry(main)>

see how the prompt morphs into a whole filesystem-aware situation? shell-mode on, shell-mode off, and you're right back to pry(main)>. chefs kiss. πŸ‘‘


🧭 State Navigation

The cd command is used to move into a new object (or scope) inside a Pry session. When inside the new scope it becomes the self for the session and all commands and methods will operate on this new self.

pry(main)> self
=> main
pry(main)> cd Pry
pry(Pry):1> self
=> Pry
pry(Pry):1> cd ..
pry(main)>

you literally just move in. new scope, new self, new you. it's giving relocation era. πŸ¦‹

The ls command is essentially a unified wrapper to a number of RubyΒ΄s introspection mechanisms, including (but not limited to) the following methods: methods, instance_variables, constants, local_variables, instance_methods, class_variables and all the various permutations thereof.

By default typing ls will return a list of just the local and instance variables available in the current context.

  • The -M option selects public instance methods (if available).
  • The -m option selects public methods.
  • The -c option selects constants.
  • The -i option select just instance variables.
  • The -l option selects just local variables.
  • The -s option modifies the -c and -m and -M options to go up the superclass chain (excluding Object).
  • The --grep REGEX prunes the list to items that match the regex.

so many flags, all of them useful, all of them yours. 🫢


πŸ” Source Browsing

Simply typing show-method method_name will pull the source for the method and display it with syntax highlighting. You can also look up the source for multiple methods at the same time, by typing show-method method1 method2. As a convenience, Pry looks up both instance methods and class methods using this syntax, with priority given to instance methods.

pry(Pry):1> show-method rep

From: /Users/john/ruby/projects/pry/lib/pry/pry_instance.rb @ line 191:
Number of lines: 6

def rep(target=TOPLEVEL_BINDING)
  target = Pry.binding_for(target)
  result = re(target)

  show_result(result) if should_print?
end

syntax highlighting AND the exact file and line number? that's not just a repl, that's a research tool. obsessed. πŸ”₯


πŸ’œ AUTHORS

Pry is primarily the work of John Mair (banisterfiend)


okay that's the whole page, bestie. every flag, every example, every file. nothing skipped, nothing watered down. you're basically a Pry expert now, iykyk. πŸ’…βœ¨

PRY(1) β€” June 2014 πŸŽ€ thank you for reading, love u, go open a repl and slay. πŸŒΈπŸ’–πŸ¦‹

πŸ“¦ where this page comes from