Pry Notes Day 2 Flashcards
what is pry?
pry is a REPL ( Read, Evaluate, Print, Loop.) Pry is an open source project developed as an alternative to IRB, the standard Ruby REPL. Pry is a much more powerful tool that allows for more efficient and effective debugging.
Think of Pry as a sandbox to test your code.
how do you install pry?
type [gem install pry] into the terminal and hit return
how do you view ruby documentation in pry?
- type [gem install pry-doc] into the terminal and hit return
how do you begin a pry session?
type [pry] into your terminal and hit return
what does [ls] do in Pry?
LS lists all the available methods in pry for a given data type.
Example: ls String
what does [show-doc] do in Pry?
shows a documentation summary for a given method.
Example:
[2] pry(main)> show-doc String#end_with?
From: string.c (C Method): Owner: String Visibility: public Signature: end_with?(*arg1) Number of lines: 7
Returns true if str ends with one of the suffixes given.
“hello”.end_with?(“ello”) #=> true
# returns true if one of the suffixes matches. "hello".end_with?("heaven", "ello") #=> true "hello".end_with?("heaven", "paradise") #=> false
WARNING: the show-doc command is deprecated. It will be removed from future Pry versions.
Please use ‘show-source’ with the -d (or –doc) switch instead
Example: show-source String#include? -d
what does [load] do in pry?
it allows you to load entire files with previously written methods into your Pry for you to use in the command line
[1] pry(main)> load “code.rb”
what does [show-source] do in pry?
If we want to see the code that implements a method, we call this the source code, we can use the show-source method.Let’s say we previously copy and pasted a definition for is_prime? into our Pry session, then we could view the original source using show-source is_prime?:
[5] pry(main)> show-source is_prime?
From: (pry) @ line 1:
Owner: Object
Visibility: public
Number of lines: 7
def is_prime?(num) (2...num).each do |factor| return false if num % factor == 0 end
num > 1
end