pry, the good parts

123

Upload: conrad-irwin

Post on 15-May-2015

1.896 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: Pry, the good parts
Page 2: Pry, the good parts

Installing Pry

• gem install pry-plus --no-ri --no-rdoc

• Pry-plus contains pry + pry-doc (documentation for C methods)+ pry-debugger (step-through debugger)+ pry-rescue (opens pry on unhandled exceptions)+ pry-stack_explorer (call-stack navigation)+ gist support, bond support, more docs…

Page 3: Pry, the good parts

What’s Pry?

• “like irb, but better”

• Pry is a REPL for Ruby– (Read-Evaluate-Print Loop)

• An aide for ruby programmers

Page 4: Pry, the good parts

Pry as an aide

• Pry doesn’t solve your problems

• Pry helps you solve your problems

• Lots of simple tools to make your life better

Page 5: Pry, the good parts

Progress

• Introduction• How do I use the Base64 library?• Why doesn’t my method work?• Where did that nil come from?• What does ordinalize actually do?• Conclusion

Page 6: Pry, the good parts

How do I use the Base64 library?

$ pry[1] pry(main)> require ‘base64’=> true[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Page 7: Pry, the good parts

How do I use the Base64 library?

$ pry[1] pry(main)> require ‘base64’=> true[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Page 8: Pry, the good parts

How do I use the Base64 library?

$ pry[1] pry(main)> require ‘base64’=> true[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Page 9: Pry, the good parts

How do I use the Base64 library?

$ pry[1] pry(main)> require ‘base64’=> true[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Page 10: Pry, the good parts

How do I use the Base64 library?

$ pry[1] pry(main)> require ‘base64’=> true[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Page 11: Pry, the good parts

How do I use the Base64 library?

$ pry[1] pry(main)> require ‘base64’=> true[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)>

Page 12: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)> (“hi”)=> “aGk=\n”[4] pry(main)> Base64.decode64(_)=> “hi”

Page 13: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)> Base64.encode64(“hi”)=> “aGk=\n”[4] pry(main)> Base64.decode64(_)=> “hi”

Page 14: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)> Base64.enc<tab>4(“hi”)=> “aGk=\n”[4] pry(main)> Base64.decode64(_)=> “hi”

Page 15: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)> Base64.encode64(“hi”)=> “aGk=\n”[4] pry(main)> Base64.decode64(_)=> “hi”

Page 16: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)> Base64.encode64 “hi”=> “aGk=\n”[4] pry(main)> Base64.decode64 _=> “hi”

Page 17: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)> Base64.encode64 “hi”=> “aGk=\n”[4] pry(main)> Base64.decode64 _=> “hi”

Page 18: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)> Base64.encode64 “hi”=> “aGk=\n”[4] pry(main)> Base64.decode64 _=> “hi”

Page 19: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[3] pry(main)> Base64.encode64 “hi”=> “aGk=\n”[4] pry(main)> Base64.decode64 _=> “hi”

Page 20: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[5] pry(main)>

Page 21: Pry, the good parts

How do I use the Base64 library?

[2] pry(main)> ls Base64Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64[5] pry(main)> ? Base64.strict_encode64

Page 22: Pry, the good parts

How do I use the Base64 library?[5] pry(main)> ? Base64.strict_encode64

From: ~/ruby-1.9.3/lib/ruby/base64.rbOwner: #<Class:Base64>Visibility: publicSignature: strict_encode64(bin)

Returns the Base64-encoded version of bin.This method complies with RFC 4648.No line feeds are added.

Page 23: Pry, the good parts

How do I use the Base64 library?[5] pry(main)> ? Base64.encode64

From: ~/ruby-1.9.3/lib/ruby/base64.rbOwner: #<Class:Base64>Visibility: publicSignature: encode64(bin)

Returns the Base64-encoded version of bin.This method complies with RFC 2045.Line feeds are added every 60 characters.

Page 24: Pry, the good parts

How do I use the Base64 library?

• Evaluate ruby code.• Colour• Tab-completion• _ (the last output)• ls (list methods)• ? (show-doc)

Page 25: Pry, the good parts

Progress

• Introduction• How do I use the Base64 library?• Why doesn’t my method work?• Where did that nil come from?• What does ordinalize actually do?• Conclusion

Page 26: Pry, the good parts

Why doesn’t my method work?

• Broken code can be downloaded if you’re following along– (n.b. /raw/ is important!)

curl https://gist.github.com/raw/4463940 > basic_auth.rb

Page 27: Pry, the good parts

Why doesn’t my method work?[1] pry(main)> cat basic_auth.rbrequire ‘base64’module BasicAuth def self.encode(username, password) s = [username, password].join(“:”) “Basic #{Base64.strict_encode64 s}” end

def self.decode(header) base64 = header[/Basic (.*)/, 1] Base64.decode64 base64.split(“:”) endend

Page 28: Pry, the good parts

Why doesn’t my method work?

[1] pry(main)> cat basic_auth.rb[2] pry(main)> require _file_=> true[3] pry(main)> BasicAuth.encode ‘hi’, ‘mum’=> “Basic aGk6bXVt”[4] pry(main)> BasicAuth.decode _NoMethodError: undefined method `unpack’ for [“aGk6bXVt”]:Array[4] pry(main)> wtf?0’

Page 29: Pry, the good parts

Why doesn’t my method work?

[1] pry(main)> cat basic_auth.rb[2] pry(main)> require _file_=> true[3] pry(main)> BasicAuth.encode ‘hi’, ‘mum’=> “Basic aGk6bXVt”[4] pry(main)> BasicAuth.decode _NoMethodError: undefined method `unpack’ for [“aGk6bXVt”]:Array[4] pry(main)> wtf?0’

Page 30: Pry, the good parts

Why doesn’t my method work?

[1] pry(main)> cat basic_auth.rb[2] pry(main)> require _file_=> true[3] pry(main)> BasicAuth.encode ‘hi’, ‘mum’=> “Basic aGk6bXVt”[4] pry(main)> BasicAuth.decode _NoMethodError: undefined method `unpack’ for [“aGk6bXVt”]:Array[5] pry(main)> wtf?0’

Page 31: Pry, the good parts

Why doesn’t my method work?

[4] pry(main)> BasicAuth.decode _NoMethodError: undefined method `unpack’ for [“aGk6bXVt”]:Array[5] pry(main)> wtf?0: ~/ruby-1.9.3/lib/ruby/base64.rb:58 in `decode’1: ~/basic_auth.rb:10 in `decode’2: (pry):3 in `__pry__’

Page 32: Pry, the good parts

Why doesn’t my method work?

[4] pry(main)> BasicAuth.decode _NoMethodError: undefined method `unpack’ for [“aGk6bXVt”]:Array[5] pry(main)> wtf? 0: ~/ruby-1.9.3/lib/ruby/base64.rb:58 in `decode64’ 1: ~/basic_auth.rb:10 in `decode’ 2: (pry):3 in `__pry__’[6] pry(main)>

Page 33: Pry, the good parts

Why doesn’t my method work?

[5] pry(main)> wtf? 0: ~/ruby-1.9.3/lib/ruby/base64.rb:58 in `decode64’ 1: ~/basic_auth.rb:10 in `decode’ 2: (pry):3 in `__pry__’[6] pry(main)> $ BasicAuth.decode

Page 34: Pry, the good parts

Why doesn’t my method work?

[5] pry(main)> wtf? 0: ~/ruby-1.9.3/lib/ruby/base64.rb:58 in `decode64’ 1: ~/basic_auth.rb:10 in `decode’ 2: (pry):3 in `__pry__’[6] pry(main)> show-source BasicAuth.decode

Page 35: Pry, the good parts

Why doesn’t my method work?

[6] pry(main)> $ BasicAuth.decode

From: ~/basic_auth.rbOwner: #<Class:BasicAuth>Visibility: publicNumber of lines: 4

def self.decode(header) base64 = header[/Basic (.*)/, 1] Base64.decode64 base64.split(“:”)end

Page 36: Pry, the good parts

Why doesn’t my method work?

[5] pry(main)> wtf? 0: ~/ruby-1.9.3/lib/ruby/base64.rb:58 in `decode64’ 1: ~/basic_auth.rb:10 in `decode’ 2: (pry):3 in `__pry__’[6] pry(main)> $ BasicAuth.decode[7] pry(main)> edit-method

Page 37: Pry, the good parts

Why doesn’t my method work?

[5] pry(main)> wtf? 0: ~/ruby-1.9.3/lib/ruby/base64.rb:58 in `decode64’ 1: ~/basic_auth.rb:10 in `decode’ 2: (pry):3 in `__pry__’[6] pry(main)> $ BasicAuth.decode[7] pry(main)> edit-method <alt+_> (on Linux)

Page 38: Pry, the good parts

Why doesn’t my method work?

[5] pry(main)> wtf? 0: ~/ruby-1.9.3/lib/ruby/base64.rb:58 in `decode64’ 1: ~/basic_auth.rb:10 in `decode’ 2: (pry):3 in `__pry__’[6] pry(main)> $ BasicAuth.decode[7] pry(main)> edit-method <esc>_ (on a Mac)

Page 39: Pry, the good parts

Why doesn’t my method work?

[5] pry(main)> wtf? 0: ~/ruby-1.9.3/lib/ruby/base64.rb:58 in `decode64’ 1: ~/basic_auth.rb:10 in `decode’ 2: (pry):3 in `__pry__’[6] pry(main)> $ BasicAuth.decode[7] pry(main)> edit-method BasicAuth.decode

Page 40: Pry, the good parts
Page 41: Pry, the good parts
Page 42: Pry, the good parts

Why doesn’t my method work?

[7] pry(main)> edit-method BasicAuth.decode[8] pry(main)>

Page 43: Pry, the good parts

Why doesn’t my method work?

[7] pry(main)> edit-method BasicAuth.decode[8] pry(main)> <ctrl+r>

Page 44: Pry, the good parts

Why doesn’t my method work?

[7] pry(main)> edit-method BasicAuth.decode[8] pry(main)>(reverse-i-search)`’:

Page 45: Pry, the good parts

Why doesn’t my method work?

[7] pry(main)> edit-method BasicAuth.decode[8] pry(main)> BasicAuth.encode ‘hi’, ‘mum’(reverse-i-search)`enc’

Page 46: Pry, the good parts

Why doesn’t my method work?

[7] pry(main)> edit-method BasicAuth.decode[8] pry(main)> BasicAuth.encode ‘hi’, ‘mum’=> “Basic aGk6bXVt”[9] pry(main)>

Page 47: Pry, the good parts

Why doesn’t my method work?

[7] pry(main)> edit-method BasicAuth.decode[8] pry(main)> BasicAuth.encode ‘hi’, ‘mum’=> “Basic aGk6bXVt”[9] pry(main)> BasicAuth.decode _=> [“hi”, “mum”][10] pry(main)>

Page 48: Pry, the good parts

Why doesn’t my method work?

[7] pry(main)> edit-method BasicAuth.decode[8] pry(main)> BasicAuth.encode ‘hi’, ‘mum’=> “Basic aGk6bXVt”[9] pry(main)> BasicAuth.decode _=> [“hi”, “mum”][10] pry(main)> BasicAuth.decode _out_[3]

Page 49: Pry, the good parts

Why doesn’t my method work?

[7] pry(main)> edit-method BasicAuth.decode[8] pry(main)> BasicAuth.encode ‘hi’, ‘mum’=> “Basic aGk6bXVt”[9] pry(main)> BasicAuth.decode _=> [“hi”, “mum”][10] pry(main)> BasicAuth.decode _out_[3]=> [“hi”, “mum”]

Page 50: Pry, the good parts

Why doesn’t my method work?

• wtf? (show backtrace, also _ex_.backtrace)• $ (show-source)• edit-method (uses $EDITOR)• <Alt+_>, <esc>_ (copy last word down)• <ctrl+r> (search history)• _file_ (last shown file, also _dir_)• _out_ (array of all output values, also _in_)

Page 51: Pry, the good parts

Progress

• Introduction• How do I use the Base64 library?• Why doesn’t my method work?• Where did that nil come from?• What does ordinalize actually do?• Conclusion

Page 52: Pry, the good parts

Where did that nil come from?

• To follow along get the next file – (the /raw/ is still important)

• curl https://gist.github.com/raw/4464704 > post.rb

Page 53: Pry, the good parts

Where did that nil come from?

$ ruby post.rbpost.rb:11:in `make_safe': undefined method `gsub' for nil:NilClass (NoMethodError)

from post.rb:7:in `safe_title'from post.rb:19:in `<main>’

$

Page 54: Pry, the good parts

Where did that nil come from?

$ ruby post.rbpost.rb:11:in `make_safe': undefined method `gsub' for nil:NilClass (NoMethodError)

from post.rb:7:in `safe_title'from post.rb:19:in `<main>’

$ subl post.rb

Page 55: Pry, the good parts
Page 56: Pry, the good parts
Page 57: Pry, the good parts

Where did that nil come from?

$ subl post.rb$

Page 58: Pry, the good parts

Where did that nil come from?

$ subl post.rb$ ruby post.rb

Page 59: Pry, the good parts

Where did that nil come from?$ subl post.rb$ ruby post.rbFrom: post.rb @ line 19 :

16: new_post = Post.new( 17: 'title' => 'new post', 18: 'body' => 'your text here') => 19: binding.pry # Added for debugging 20: puts new_post.safe_title

[1] pry(main)>

Page 60: Pry, the good parts

Where did that nil come from?$ subl post.rb$ ruby post.rbFrom: post.rb @ line 19 :

16: new_post = Post.new( 17: 'title' => 'new post', 18: 'body' => 'your text here') => 19: binding.pry # Added for debugging 20: puts new_post.safe_title

[1] pry(main)> puts new_post.safe_title

Page 61: Pry, the good parts

Where did that nil come from?$ subl post.rb$ ruby post.rbFrom: post.rb @ line 19 :

16: new_post = Post.new( 17: 'title' => 'new post', 18: 'body' => 'your text here') => 19: binding.pry # Added for debugging 20: puts new_post.safe_title

[1] pry(main)> puts new_post.safe_titleNoMethodError: undefined method `gsub' for nil

Page 62: Pry, the good parts

Where did that nil come from?[1] pry(main)> puts new_post.safe_titleNoMethodError: undefined method `gsub' for nil[2] pry(main)>

Page 63: Pry, the good parts

Where did that nil come from?[1] pry(main)> puts new_post.safe_titleNoMethodError: undefined method `gsub' for nil[2] pry(main)> cd new_post

Page 64: Pry, the good parts

Where did that nil come from?[1] pry(main)> puts new_post.safe_titleNoMethodError: undefined method `gsub' for nil[2] pry(main)> cd new_post[3] pry(#<Post>):1>

Page 65: Pry, the good parts

Where did that nil come from?[1] pry(main)> puts new_post.safe_titleNoMethodError: undefined method `gsub' for nil[2] pry(main)> cd new_post[3] pry(#<Post>):1> ls

Page 66: Pry, the good parts

Where did that nil come from?[1] pry(main)> puts new_post.safe_titleNoMethodError: undefined method `gsub' for nil[2] pry(main)> cd new_post[3] pry(#<Post>):1> lsPost#methods: make_safe safe_titleinstance variables: @paramslocals: _ _dir_ _ex_ _file_ _in_ _out_ _pry_[4] pry(#<Post>):1>

Page 67: Pry, the good parts

Where did that nil come from?[1] pry(main)> puts new_post.safe_titleNoMethodError: undefined method `gsub' for nil[2] pry(main)> cd new_post[3] pry(#<Post>):1> lsPost#methods: make_safe safe_titleinstance variables: @paramslocals: _ _dir_ _ex_ _file_ _in_ _out_ _pry_[4] pry(#<Post>):1> $ safe_title

Page 68: Pry, the good parts

Where did that nil come from?[1] pry(main)> puts new_post.safe_titleNoMethodError: undefined method `gsub' for nil[2] pry(main)> cd new_post[3] pry(#<Post>):1> lsPost#methods: make_safe safe_titleinstance variables: @paramslocals: _ _dir_ _ex_ _file_ _in_ _out_ _pry_[4] pry(#<Post>):1> $ Post#safe_title

Page 69: Pry, the good parts

Where did that nil come from?[4] pry(#<Post>):1> $ safe_titleFrom: post.rb @ line 7:Number of lines: 3Owner: PostVisibility: public

def safe_title make_safe @params[:title]end[5] pry(#<Post>):1>

Page 70: Pry, the good parts

Where did that nil come from?[4] pry(#<Post>):1> $ safe_titleFrom: post.rb @ line 7:Number of lines: 3Owner: PostVisibility: public

def safe_title make_safe @params[:title]end[5] pry(#<Post>):1> @params

Page 71: Pry, the good parts

Where did that nil come from?[4] pry(#<Post>):1> $ safe_titleFrom: post.rb @ line 7:Number of lines: 3Owner: PostVisibility: public

def safe_title make_safe @params[:title]end[5] pry(#<Post>):1> @params{“title”=>”new post”, “body”=>”your text here”}[6] pry(#<Post>):1>

Page 72: Pry, the good parts

Where did that nil come from?[4] pry(#<Post>):1> $ safe_titleFrom: post.rb @ line 7:Number of lines: 3Owner: PostVisibility: public

def safe_title make_safe @params[:title]end[5] pry(#<Post>):1> @params{“title”=>”new post”, “body”=>”your text here”}[6] pry(#<Post>):1> edit --ex

Page 73: Pry, the good parts
Page 74: Pry, the good parts
Page 75: Pry, the good parts

Where did that nil come from?

[5] pry(#<Post>):1> @params{“title”=>”new post”, “body”=>”your text here”}[6] pry(#<Post>):1> edit --ex[7] pry(#<Post>):1>

Page 76: Pry, the good parts

Where did that nil come from?

[5] pry(#<Post>):1> @params{“title”=>”new post”, “body”=>”your text here”}[6] pry(#<Post>):1> edit --ex[7] pry(#<Post>):1> .git diff

Page 77: Pry, the good parts

Where did that nil come from?[7] pry(#<Post>):1> .git diffdiff --git a/post.rb b/post.rbindex d0ed356..057d37c 100644--- a/post.rb+++ b/post.rb@@ -4, 7 +4,7 @@ class Post end

def safe_title- make_safe @params[:title] + make_safe @params[‘title’] end [8] pry(#<Post>):1>

Page 78: Pry, the good parts

Where did that nil come from?[7] pry(#<Post>):1> .git diffdiff --git a/post.rb b/post.rbindex d0ed356..057d37c 100644--- a/post.rb+++ b/post.rb@@ -4, 7 +4,7 @@ class Post end

def safe_title- make_safe @params[:title]+ make_safe @params[‘title’] end [8] pry(#<Post>):1> cd ..

Page 79: Pry, the good parts

Where did that nil come from?[8] pry(#<Post>):1> cd ..[9] pry(main)>

Page 80: Pry, the good parts

Where did that nil come from?[8] pry(#<Post>):1> cd ..[9] pry(main)> whereami

Page 81: Pry, the good parts

Where did that nil come from?[8] pry(#<Post>):1> cd ..[9] pry(main)> whereamiFrom: post.rb @ line 19 :

16: new_post = Post.new( 17: 'title' => 'new post', 18: 'body' => 'your text here') => 19: binding.pry # Added for debugging 20: puts new_post.safe_title[10] pry(main)>

Page 82: Pry, the good parts

Where did that nil come from?[8] pry(#<Post>):1> cd ..[9] pry(main)> whereamiFrom: post.rb @ line 19 :

16: new_post = Post.new( 17: 'title' => 'new post', 18: 'body' => 'your text here') => 19: binding.pry # Added for debugging 20: puts new_post.safe_title[10] pry(main)> puts new_post.safe_title

Page 83: Pry, the good parts

Where did that nil come from?[9] pry(main)> whereamiFrom: post.rb @ line 19 :

16: new_post = Post.new( 17: 'title' => 'new post', 18: 'body' => 'your text here') => 19: binding.pry # Added for debugging 20: puts new_post.safe_title[10] pry(main)> puts new_post.safe_titlenew-post=> nil[11] pry(main)>

Page 84: Pry, the good parts

Where did that nil come from?[10] pry(main)> puts new_post.safe_titlenew-post=> nil[11] pry(main)> puts new_post.safe_title;

Page 85: Pry, the good parts

Where did that nil come from?[10] pry(main)> puts new_post.safe_titlenew-post=> nil[11] pry(main)> puts new_post.safe_title;new-post[12] pry(main)>

Page 86: Pry, the good parts

Where did that nil come from?[10] pry(main)> puts new_post.safe_titlenew-post=> nil[11] pry(main)> puts new_post.safe_title;new-post[12] pry(main)> <ctrl+d>

Page 87: Pry, the good parts

Where did that nil come from?

• binding.pry (open pry right here, right now)• cd (change self)• whereami• edit --ex (also, edit -i)• . (run’s shell commands)• <ctrl-d> (cd .. or exit)• ; (suppress output)

Page 88: Pry, the good parts

Progress

• Introduction• How do I use the Base64 library?• Why doesn’t my method work?• Where did that nil come from?• What does ordinalize actually do?• Conclusion

Page 89: Pry, the good parts

What does ordinalize actually do?

[1] pry(main)>

Page 90: Pry, the good parts

What does ordinalize actually do?

[1] pry(main)> help gem

Page 91: Pry, the good parts

What does ordinalize actually do?

[1] pry(main)> help gemGems gem-cd Change working directory to specified gem's directory. gem-install Install a gem and refresh the gem cache. gem-list List and search installed gems. gem-open Opens the working directory of the gem in your editor.[2] pry(main)>

Page 92: Pry, the good parts

What does ordinalize actually do?

[1] pry(main)> help gemGems gem-cd Change working directory to specified gem's directory. gem-install Install a gem and refresh the gem cache. gem-list List and search installed gems. gem-open Opens the working directory of the gem in your editor.[2] pry(main)> help gem-install

Page 93: Pry, the good parts

What does ordinalize actually do?

[1] pry(main)> help gemGems gem-cd Change working directory to specified gem's directory. gem-install Install a gem and refresh the gem cache. gem-list List and search installed gems. gem-open Opens the working directory of the gem in your editor.[2] pry(main)> gem-install --help

Page 94: Pry, the good parts

What does ordinalize actually do?

[2] pry(main)> gem-install --helpUsage: gem-install GEM_NAME

Installs the given gem and refreshes the gem cache so that you can immediately 'require GEM_FILE'

-h, --help Show this message.[3] pry(main)>

Page 95: Pry, the good parts

What does ordinalize actually do?

[1] pry(main)> help gem[2] pry(main)> gem-install --help[3] pry(main)> gem-install activesupport

Page 96: Pry, the good parts

What does ordinalize actually do?

[3] pry(main)> gem-install activesupportFetching: i18n-0.6.1.gem (100%)Fetching: multi_json-1.5.0.gem (100%)Fetching: activesupport-3.2.10.gem (100%)Gem `activesupport` installed.[4] pry(main)>

Page 97: Pry, the good parts

What does ordinalize actually do?

[3] pry(main)> gem-install activesupportFetching: i18n-0.6.1.gem (100%)Fetching: multi_json-1.5.0.gem (100%)Fetching: activesupport-3.2.10.gem (100%)Gem `activesupport` installed.[3] pry(main)> require ‘active_support/core_ext’

Page 98: Pry, the good parts

What does ordinalize actually do?

[3] pry(main)> gem-install activesupportFetching: i18n-0.6.1.gem (100%)Fetching: multi_json-1.5.0.gem (100%)Fetching: activesupport-3.2.10.gem (100%)Gem `activesupport` installed.[4] pry(main)> require ‘active_support/core_ext’=> true[5] pry(main)>

Page 99: Pry, the good parts

What does ordinalize actually do?

[3] pry(main)> gem-install activesupportFetching: i18n-0.6.1.gem (100%)Fetching: multi_json-1.5.0.gem (100%)Fetching: activesupport-3.2.10.gem (100%)Gem `activesupport` installed.[4] pry(main)>require ‘active_support/core_ext’=> true[5] pry(main)> 5.ordinalize=> “5th”[6] pry(main)>

Page 100: Pry, the good parts

What does ordinalize actually do?

[3] pry(main)> gem-install activesupportFetching: i18n-0.6.1.gem (100%)Fetching: multi_json-1.5.0.gem (100%)Fetching: activesupport-3.2.10.gem (100%)Gem `activesupport` installed.[4] pry(main)>require ‘active_support/core_ext’=> True[5] pry(main)> 5.ordinalize=> “5th”[6] pry(main)> break Fixnum#ordinalize

Page 101: Pry, the good parts

What does ordinalize actually do?

[6] pry(main)> break Fixnum#ordinalizeBreakpoint 1: core_ext/integer/inflections.rb:14

12: # -1001.ordinalize # => "-1001st" 13: # => 14: def ordinalize 15: Inflector.ordinalize(self) 16: end 17: end

[7] pry(main)>

Page 102: Pry, the good parts

What does ordinalize actually do?

[6] pry(main)> break Fixnum#ordinalizeBreakpoint 1: core_ext/integer/inflections.rb:14

12: # -1001.ordinalize # => "-1001st" 13: # => 14: def ordinalize 15: Inflector.ordinalize(self) 16: end 17: end

[7] pry(main)> 5.ordinalize

Page 103: Pry, the good parts

What does ordinalize actually do?

[7] pry(main)> 5.ordinalizeBreakpoint 1. First hit.

From: core_ext/integer/inflections.rb:14:

=> 14: def ordinalize 15: Inflector.ordinalize(self) 16: end

[8] pry(5)>

Page 104: Pry, the good parts

What does ordinalize actually do?

[7] pry(main)> 5.ordinalizeBreakpoint 1. First hit.

From: core_ext/integer/inflections.rb:14:

=> 14: def ordinalize 15: Inflector.ordinalize(self) 16: end

[8] pry(5)> step

Page 105: Pry, the good parts

What does ordinalize actually do?

[8] pry(5)> stepFrom: core_ext/integer/inflections.rb:15:

14: def ordinalize => 15: Inflector.ordinalize(self) 16: end

[9] pry(5)>

Page 106: Pry, the good parts

What does ordinalize actually do?

[8] pry(5)> stepFrom: core_ext/integer/inflections.rb:15:

14: def ordinalize => 15: Inflector.ordinalize(self) 16: end

[9] pry(5)> step

Page 107: Pry, the good parts

What does ordinalize actually do? [9] pry(5)> stepFrom: active_support/inflector/methods.rb:280 279: def ordinalize(number) => 280: if (11..13).include?(number.to_i.abs % 100) 281: "#{number}th" 282: else 283: case number.to_i.abs % 10 284: when 1; "#{number}st" 285: when 2; "#{number}nd" 286: when 3; "#{number}rd" 287: else "#{number}th" 288: end 289: end 290: end

[10] pry(ActiveSupport::Inflector)>

Page 108: Pry, the good parts

What does ordinalize actually do? [9] pry(5)> stepFrom: active_support/inflector/methods.rb:280 279: def ordinalize(number) => 280: if (11..13).include?(number.to_i.abs % 100) 281: "#{number}th" 282: else 283: case number.to_i.abs % 10 284: when 1; "#{number}st" 285: when 2; "#{number}nd" 286: when 3; "#{number}rd" 287: else "#{number}th" 288: end 289: end 290: end

[10] pry(ActiveSupport::Inflector)> next

Page 109: Pry, the good parts

What does ordinalize actually do? [10] pry(ActiveSupport::Inflector)> nextFrom: active_support/inflector/methods.rb:283 279: def ordinalize(number) 280: if (11..13).include?(number.to_i.abs % 100) 281: "#{number}th" 282: else => 283: case number.to_i.abs % 10 284: when 1; "#{number}st" 285: when 2; "#{number}nd" 286: when 3; "#{number}rd" 287: else "#{number}th" 288: end 289: end 290: end

[11] pry(ActiveSupport::Inflector)>

Page 110: Pry, the good parts

What does ordinalize actually do? [10] pry(ActiveSupport::Inflector)> nextFrom: active_support/inflector/methods.rb:283 279: def ordinalize(number) 280: if (11..13).include?(number.to_i.abs % 100) 281: "#{number}th" 282: else => 283: case number.to_i.abs % 10 284: when 1; "#{number}st" 285: when 2; "#{number}nd" 286: when 3; "#{number}rd" 287: else "#{number}th" 288: end 289: end 290: end

[11] pry(ActiveSupport::Inflector)> next

Page 111: Pry, the good parts

What does ordinalize actually do? [11] pry(ActiveSupport::Inflector)> nextFrom: active_support/inflector/methods.rb:287 279: def ordinalize(number) 280: if (11..13).include?(number.to_i.abs % 100) 281: "#{number}th" 282: else 283: case number.to_i.abs % 10 284: when 1; "#{number}st" 285: when 2; "#{number}nd" 286: when 3; "#{number}rd" => 287: else "#{number}th" 288: end 289: end 290: end

[12] pry(ActiveSupport::Inflector)>

Page 112: Pry, the good parts

What does ordinalize actually do? [11] pry(ActiveSupport::Inflector)> nextFrom: active_support/inflector/methods.rb:287 279: def ordinalize(number) 280: if (11..13).include?(number.to_i.abs % 100) 281: "#{number}th" 282: else 283: case number.to_i.abs % 10 284: when 1; "#{number}st" 285: when 2; "#{number}nd" 286: when 3; "#{number}rd" => 287: else "#{number}th" 288: end 289: end 290: end

[12] pry(ActiveSupport::Inflector)> continue

Page 113: Pry, the good parts

What does ordinalize actually do? [12] pry(ActiveSupport::Inflector)> continue=> “5th”[13] pry(main)>

Page 114: Pry, the good parts

What does ordinalize actually do? [12] pry(ActiveSupport::Inflector)> continue=> “5th”[13] pry(main)> gist -m ActiveSupport::Inflector.ordinalize

Page 115: Pry, the good parts

What does ordinalize actually do? [12] pry(ActiveSupport::Inflector)> continue=> “5th”[13] pry(main)> gist –m ActiveSupport::Inflector.ordinalizeGist created at https://gist.github.com/465407823ee6182d8833 and added to clipboard.[14] pry(main)>

Page 116: Pry, the good parts

What does ordinalize actually do? [12] pry(ActiveSupport::Inflector)> continue=> “5th”[13] pry(main)> gist –m ActiveSupport::Inflector.ordinalizeGist created at https://gist.github.com/465407823ee6182d8833 and added to clipboard,[14] pry(main)> !!!

Page 117: Pry, the good parts

What does ordinalize actually do? [12] pry (ActiveSupport::Inflector)> continue=> “5th”[13] pry(main)> gist –m ActiveSupport::Inflector.ordinalizeGist created at https://gist.github.com/465407823ee6182d8833 and added to clipboard,[14] pry(main)> !!!$

Page 118: Pry, the good parts

What does ordinalize actually do?

• help (and --help)• break (pry-debugger)• step/next/continue (pry-debugger)• gist• gem-install (-cd, -open, -list)• !!! (exit)

Page 119: Pry, the good parts

Progress

• Introduction• How do I use the Base64 library?• Why doesn’t my method work?• Where did that nil come from?• What does ordinalize actually do?• Conclusion

Page 120: Pry, the good parts

More good plugins (pry-plus)!

• pry-rescue– Automatic binding.pry where-ever you have an

unhandled exception or test failure.• pry-stack_explorer– Lets you move up-and-down the callstack.

• pry-doc, pry-docmore– ?/show-doc for C methods, ruby syntax

• bond– Better-yet tab completion

Page 121: Pry, the good parts

Configuration

• Configuration– ./.pryrc and ~/.pryrc

• Custom commands Pry.commands.add_command ‘test’ do output.puts “test” end

• Documentation on the wiki

Page 122: Pry, the good parts

There’s still more…Help help Show a list of commands. Type help <foo> for information about <foo>.

Context cd Move into a new context (object or scope). find-method Recursively search for a method within a Class/Module or the current namespace. fin ls Show the list of vars and methods in the current scope. pry-backtrace Show the backtrace for the Pry session. raise-up Raise an exception out of the current pry instance. reset Reset the REPL to a clean state. whereami Show code surrounding the current context. wtf? Show the backtrace of the most recent exception

Editing ! Clear the input buffer. Useful if the parsing process goes wrong and you get stuck amend-line Amend a line of input in multi-line mode. edit Invoke the default editor on a file. edit-method Edit the source code for a method. hist Show and replay Readline history. Aliases: history play Play back a string variable or a method or a file as input. show-input Show the contents of the input buffer for the current multi-line expression.

Introspection ri View ri documentation. e.g ri Array#each show-command Show the source for CMD. show-source Show the source for a method or class. Aliases: $, show-method stat View method information and set _file_ and _dir_ locals.

Input and output .<shell command> All text following a '.' is forwarded to the shell. cat Show code from a file, Pry's input buffer, or the last exception. save-file Export to a file using content from the REPL. shell-mode Toggle shell mode. Bring in pwd prompt and file completion.

Navigating pry !pry Start a Pry session on current self; this even works mid multi-line expression. exit Pop the previous binding (does NOT exit program). Aliases: quit exit-all End the current Pry session (popping all bindings) and returning to caller. Accepts exit-program End the current program. Aliases: quit-program, !!! jump-to Jump to a binding further up the stack, popping all bindings below. nesting Show nesting information. switch-to Start a new sub-session on a binding in the current stack (numbered by nesting).

Gems gem-cd Change working directory to specified gem's directory. gem-install Install a gem and refresh the gem cache. gem-list List and search installed gems.

Commands import-set Import a command set install-command Install a disabled command.

Aliases !!! Alias for exit-program !!@ Alias for exit-all $ Alias for show-source ? Alias for show-doc breakpoint Alias for break breaks Alias for breakpoints clipit Alias for gist --clip

file-mode Alias for shell-mode history Alias for hist jist Alias for gist quit Alias for exit quit-program Alias for exit-program show-method Alias for show-source

Gist gist Gist a method or expression history to GitHub.

Misc pry-version Show Pry version. reload-method Reload the source file that contains the specified method simple-prompt Toggle the simple prompt. toggle-color Toggle syntax highlighting.

pry-debugger (v0.2.1) break Set or edit a breakpoint. breakpoints List defined breakpoints. continue Continue program execution and end the Pry session. finish Execute until current stack frame returns. next Execute the next line within the current stack frame. step Step execution into the next line or method.

pry-docmore (v0.0.3) show-doc Show the documentation for a method/class/keyword/global. Aliases: ? show-docmores List keywords and vars covered by pry-docmore

pry-exception_explorer (v0.2.3) continue-exception Attempt to continue the current exception. enter-exception Enter the context of the last exception exit-exception Leave the context of the current exception.

pry-popularity (v0.0.3) pry-popularity Sort pry input history by frequency of use

pry-rescue (v0.14) cd-cause Move to the previously raised exception try-again Re-try the code that caused this exception

pry-stack_explorer (v0.4.7) down Go down to the callee's context. frame Switch to a particular frame. show-stack Show all frames up Go up to the caller's context.

*** REMOTE GEMS ***

pry-awesome_print (9.6.5)pry-bot (0.0.1)pry-buffers (1.0.0)pry-capture (1.0)pry-clipboard (0.1.1)pry-coolline (0.1.5)pry-de (0.1.0)pry-debugger (0.2.1)pry-debundle (0.6)pry-developer_tools (0.1.1)pry-disasm (0.0.1)pry-doc (0.4.4)pry-docmore (0.0.3)pry-editline (1.1.1)pry-em (0.2.1)pry-exception_explorer (0.2.3)pry-full (1.2.0)pry-full18 (0.4)pry-gist (5.1.12)pry-git (0.2.3)pry-github (0.0.2)pry-hack (0.1)pry-highlight (0.0.1)pry-multi_debugger (4.8.15)pry-nav (0.2.3)pry-note (0.2.9)pry-padrino (0.1.2)pry-plus (0.2.0)pry-popularity (0.0.3)pry-pretty-numeric (0.1.1)pry-rails (0.2.2)pry-remote (0.1.6)pry-remote-auto (1.1.0)pry-remote-em (0.7.3)pry-rescue (0.14)pry-stack_explorer (0.4.7)pry-syntax-hacks (0.0.6)pry-theme (0.1.3)pry-vterm_aliases (1.0.0)

Page 123: Pry, the good parts

Thanks!

• Pry– http://pryrepl.org– https://github.com/pry/pry– irc://irc.freenode.net#pry

• Conrad Irwin– http://twitter.com/ConradIrwin– https://github.com/ConradIrwin– irc://irc.freenode.net/cirwin