Pry Notes Day 2 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

what is pry?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how do you install pry?

A

type [gem install pry] into the terminal and hit return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how do you view ruby documentation in pry?

A
  1. type [gem install pry-doc] into the terminal and hit return
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how do you begin a pry session?

A

type [pry] into your terminal and hit return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what does [ls] do in Pry?

A

LS lists all the available methods in pry for a given data type.
Example: ls String

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does [show-doc] do in Pry?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what does [load] do in pry?

A

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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what does [show-source] do in pry?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly