Slide 1

Slide 1 text

group :development do gem ‘pry-rails’ gem ‘pry-plus’ end

Slide 2

Slide 2 text

What’s  Pry?   •   “like  irb,  but  be4er”     •  Everything  you  need  to  program  in  Ruby   •  (apart  from  a  text  editor)     •  60%  of  your  Fme  is  spent  debugging!        

Slide 3

Slide 3 text

Brief  history   •  2010:  John  Mair  (@banisterfiend)  created  pry   •  2011:  Ryan  Fitzgerald  (@rrff__)  and  I  joined  in   •  2012:  reached  1,000,000  downloads   –  Kyrylo  Silin  (@kyrylosilin)  and  rking   (@sharpsawDOTorg)  started  contribuFng   •  2013:  reached  2,000,000  downloads   –  71  disFnct  contributors  

Slide 4

Slide 4 text

Debugging  a  blog  engine   •  IntroducFon   •  How  do  I  use  the  Base64  library?   •  Why  doesn’t  my  method  work?   •  Where  did  that  nil  come  from?   •  Further  reading  

Slide 5

Slide 5 text

How  do  I  use  the  Base64  library?     $ pry [1] pry(main)> require ‘base64’ => true [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Slide 6

Slide 6 text

How  do  I  use  the  Base64  library?     $ pry pry [1] pry(main)> require ‘base64’ => true [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Slide 7

Slide 7 text

How  do  I  use  the  Base64  library?     $ pry [1] pry(main)> require ‘base64’ => true [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Slide 8

Slide 8 text

How  do  I  use  the  Base64  library?     $ pry [1] pry(main)> require ‘base64’ => true [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Slide 9

Slide 9 text

How  do  I  use  the  Base64  library?     $ pry [1] pry(main)> require ‘base64’ => true [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Slide 10

Slide 10 text

How  do  I  use  the  Base64  library?     $ pry [1] pry(main)> require ‘base64’ => true [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64

Slide 11

Slide 11 text

How  do  I  use  the  Base64  library?     $ pry [1] pry(main)> require ‘base64’ => true [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64 [3] pry(main)>

Slide 12

Slide 12 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64 [3] pry(main)> (“hi”) => “aGk=\n” [4] pry(main)> Base64.decode64(_) => “hi”

Slide 13

Slide 13 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.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”

Slide 14

Slide 14 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64 [3] pry(main)> Base64.enc4(“hi”) => “aGk=\n” [4] pry(main)> Base64.decode64(_) => “hi”

Slide 15

Slide 15 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.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”

Slide 16

Slide 16 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.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”

Slide 17

Slide 17 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.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”

Slide 18

Slide 18 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.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”

Slide 19

Slide 19 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.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”

Slide 20

Slide 20 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.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”

Slide 21

Slide 21 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64 [5] pry(main)>

Slide 22

Slide 22 text

How  do  I  use  the  Base64  library?   [2] pry(main)> ls Base64 Base64.methods: decode64 encode64 strict_decode64 strict_encode64 urlsafe_decode64 urlsafe_encode64 [5] pry(main)> ? Base64.strict_encode64

Slide 23

Slide 23 text

How  do  I  use  the  Base64  library?   [5] pry(main)> ? Base64.strict_encode64 From: ~/ruby-1.9.3/lib/ruby/base64.rb Owner: # Visibility: public Signature: strict_encode64(bin) Returns the Base64-encoded version of bin. This method complies with RFC 4648. No line feeds are added.

Slide 24

Slide 24 text

How  do  I  use  the  Base64  library?   [5] pry(main)> ? Base64.encode64 From: ~/ruby-1.9.3/lib/ruby/base64.rb Owner: # Visibility: public Signature: encode64(bin) Returns the Base64-encoded version of bin. This method complies with RFC 2045. Line feeds are added every 60 characters.

Slide 25

Slide 25 text

How  do  I  use  the  Base64  library?   •  Evaluate  ruby  code.   •  Colour   •  Tab-­‐compleFon   •  _  (the  last  output)   •  ls  (list  methods)   •  ?  (show-­‐doc)  

Slide 26

Slide 26 text

Debugging  a  blog  engine   •  IntroducFon   •  How  do  I  use  the  Base64  library?   •  Why  doesn’t  my  method  work?   •  Where  did  that  nil  come  from?   •  Further  reading  

Slide 27

Slide 27 text

Why  doesn’t  my  method  work?   [1] pry(main)> cat basic_auth.rb require ‘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(“:”) end end

Slide 28

Slide 28 text

Why  doesn’t  my  method  work?   [1] pry(main)> cat basic_auth.rb require ‘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(“:”) end end

Slide 29

Slide 29 text

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’

Slide 30

Slide 30 text

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’

Slide 31

Slide 31 text

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’

Slide 32

Slide 32 text

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’

Slide 33

Slide 33 text

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’

Slide 34

Slide 34 text

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__’

Slide 35

Slide 35 text

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)>

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Why  doesn’t  my  method  work?   [6] pry(main)> $ BasicAuth.decode From: ~/basic_auth.rb Owner: # Visibility: public Number of lines: 4 def self.decode(header) base64 = header[/Basic (.*)/, 1] Base64.decode64 base64.split(“:”) end

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Why  doesn’t  my  method  work?   [6] pry(main)> $ BasicAuth.decode [7] pry(main)> edit

Slide 41

Slide 41 text

Why  doesn’t  my  method  work?   [6] pry(main)> $ BasicAuth.decode [7] pry(main)> edit (on Linux) _ (on a Mac)

Slide 42

Slide 42 text

Why  doesn’t  my  method  work?   [6] pry(main)> $ BasicAuth.decode [7] pry(main)> edit BasicAuth.decode

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

Why  doesn’t  my  method  work?   [7] pry(main)> edit BasicAuth.decode [8] pry(main)>

Slide 46

Slide 46 text

Why  doesn’t  my  method  work?   [7] pry(main)> edit BasicAuth.decode [8] pry(main)>

Slide 47

Slide 47 text

Why  doesn’t  my  method  work?   [7] pry(main)> edit BasicAuth.decode [8] pry(main)> (reverse-i-search)`’:

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

Why  doesn’t  my  method  work?   [7] pry(main)> edit BasicAuth.decode [8] pry(main)> BasicAuth.encode ‘hi’, ‘mum’ => “Basic aGk6bXVt” [9] pry(main)>

Slide 50

Slide 50 text

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

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

Why  doesn’t  my  method  work?   •  wd?  (show  backtrace,  also  _ex_.backtrace)   •  $  (show-­‐source)   •  edit  (uses  $EDITOR)   •  ,  _  (copy  last  word  down)   •   (search  history)   •  _file_  (last  shown  file,  also  _dir_)   •  _out_  (array  of  all  output  values,  also  _in_)  

Slide 53

Slide 53 text

Debugging  a  blog  engine   •  IntroducFon   •  How  do  I  use  the  Base64  library?   •  Why  doesn’t  my  method  work?   •  Where  did  that  nil  come  from?   •  Further  reading  

Slide 54

Slide 54 text

Where  did  that  nil  come  from?   $ ruby post.rb post.rb:11:in `make_safe': undefined method `gsub' for nil:NilClass (NoMethodError) from post.rb:7:in `safe_title' from post.rb:19:in `’ $

Slide 55

Slide 55 text

Where  did  that  nil  come  from?   $ ruby post.rb post.rb:11:in `make_safe': undefined method `gsub' for nil:NilClass (NoMethodError) from post.rb:7:in `safe_title' from post.rb:19:in `’ $ subl post.rb

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Where  did  that  nil  come  from?   $ subl post.rb $  

Slide 59

Slide 59 text

Where  did  that  nil  come  from?   $ subl post.rb $ ruby post.rb  

Slide 60

Slide 60 text

Where  did  that  nil  come  from?   $ subl post.rb $ ruby post.rb From: post.rb @ line 18 : 15: new_post = Post.new( 16: 'title' => 'new post', 17: 'body' => 'your text here') => 18: binding.pry # Added for debugging 19: puts new_post.safe_title [1] pry(main)>

Slide 61

Slide 61 text

Where  did  that  nil  come  from?   $ subl post.rb $ ruby post.rb From: post.rb @ line 18 : 15: new_post = Post.new( 16: 'title' => 'new post', 17: 'body' => 'your text here') => 18: binding.pry # Added for debugging 19: puts new_post.safe_title [1] pry(main)> play –l 19

Slide 62

Slide 62 text

Where  did  that  nil  come  from?   $ subl post.rb $ ruby post.rb From: post.rb @ line 18 : 15: new_post = Post.new( 16: 'title' => 'new post', 17: 'body' => 'your text here') => 18: binding.pry # Added for debugging 19: puts new_post.safe_title [1] pry(main)> puts new_post.safe_title

Slide 63

Slide 63 text

Where  did  that  nil  come  from?   $ subl post.rb $ ruby post.rb From: post.rb @ line 18 : 15: new_post = Post.new( 16: 'title' => 'new post', 17: 'body' => 'your text here') => 18: binding.pry # Added for debugging 19: puts new_post.safe_title [1] pry(main)> play –l 19 NoMethodError: undefined method `gsub' for nil

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

Where  did  that  nil  come  from?   [1] pry(main)> puts new_post.safe_title NoMethodError: undefined method `gsub' for nil [2] pry(main)> cd new_post [3] pry(#):1> ls Post#methods: make_safe safe_title instance variables: @params locals: _ _dir_ _ex_ _file_ _in_ _out_ _pry_ [4] pry(#):1>

Slide 69

Slide 69 text

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

Slide 70

Slide 70 text

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

Slide 71

Slide 71 text

Where  did  that  nil  come  from?   [4] pry(#):1> $ safe_title From: post.rb @ line 7: Number of lines: 3 Owner: Post Visibility: public def safe_title make_safe @params[:title] end [5] pry(#):1>

Slide 72

Slide 72 text

Where  did  that  nil  come  from?   [4] pry(#):1> $ safe_title From: post.rb @ line 7: Number of lines: 3 Owner: Post Visibility: public def safe_title make_safe @params[:title] end [5] pry(#):1> @params

Slide 73

Slide 73 text

Where  did  that  nil  come  from?   [4] pry(#):1> $ safe_title From: post.rb @ line 7: Number of lines: 3 Owner: Post Visibility: public def safe_title make_safe @params[:title] end [5] pry(#):1> @params {“title”=>”new post”, “body”=>”your text here”} [6] pry(#):1>

Slide 74

Slide 74 text

Where  did  that  nil  come  from?   [4] pry(#):1> $ safe_title From: post.rb @ line 7: Number of lines: 3 Owner: Post Visibility: public def safe_title make_safe @params[:title] end [5] pry(#):1> @params {“title”=>”new post”, “body”=>”your text here”} [6] pry(#):1> edit --ex

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

Where  did  that  nil  come  from?   [5] pry(#):1> @params {“title”=>”new post”, “body”=>”your text here”} [6] pry(#):1> edit --ex [7] pry(#):1>

Slide 78

Slide 78 text

Where  did  that  nil  come  from?   [5] pry(#):1> @params {“title”=>”new post”, “body”=>”your text here”} [6] pry(#):1> edit --ex [7] pry(#):1> .git diff

Slide 79

Slide 79 text

Where  did  that  nil  come  from?   [7] pry(#):1> .git diff diff --git a/post.rb b/post.rb index 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(#):1>

Slide 80

Slide 80 text

Where  did  that  nil  come  from?   [7] pry(#):1> .git diff diff --git a/post.rb b/post.rb index 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(#):1> cd ..

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

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

Slide 83

Slide 83 text

Where  did  that  nil  come  from?   [8] pry(#):1> cd .. [9] pry(main)> whereami From: post.rb @ line 18 : 15: new_post = Post.new( 16: 'title' => 'new post', 17: 'body' => 'your text here') => 18: binding.pry # Added for debugging 19: puts new_post.safe_title [10] pry(main)>

Slide 84

Slide 84 text

Where  did  that  nil  come  from?   [8] pry(#):1> cd .. [9] pry(main)> whereami From: post.rb @ line 18 : 15: new_post = Post.new( 16: 'title' => 'new post', 17: 'body' => 'your text here') => 18: binding.pry # Added for debugging 19: puts new_post.safe_title [10] pry(main)> puts new_post.safe_title

Slide 85

Slide 85 text

Where  did  that  nil  come  from?   [9] pry(main)> whereami From: post.rb @ line 18 : 15: new_post = Post.new( 16: 'title' => 'new post', 17: 'body' => 'your text here') => 18: binding.pry # Added for debugging 19: puts new_post.safe_title [10] pry(main)> puts new_post.safe_title new-post => nil [11] pry(main)>

Slide 86

Slide 86 text

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

Slide 87

Slide 87 text

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

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

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

Slide 90

Slide 90 text

Where  did  that  nil  come  from?   •  binding.pry  (open  pry  right  here,  right  now)   •  cd  (change  self)   •  whereami   •  edit  -­‐-­‐ex   •  play  -­‐l   •  .  (run’s  shell  commands)   •   (cd  ..  or  exit)   •  ;  (at  end  of  line,  hides  output)  

Slide 91

Slide 91 text

Debugging  a  blog  engine   •  IntroducFon   •  How  do  I  use  the  Base64  library?   •  Why  doesn’t  my  method  work?   •  Where  did  that  nil  come  from?   •  Further  reading  

Slide 92

Slide 92 text

pry-­‐rescue/pry-­‐stack_explorer   •  pry-­‐rescue   – AutomaFcally  opens  pry  wherever  you  have  an   unhandled  excepFon  or  test  failure.   – cd-­‐cause  lets  you  pry  into  any  excepFon  that   happens  inside  the  console       •  pry-­‐stack_explorer   – lets  you  move  up/down  the  callstack  as  though   you  had  a  binding.pry  at  every  level    

Slide 93

Slide 93 text

be4er_errors   •  BetterErrors.use_pry! •  Opens  a  web  page  on  unhandled  excepFons   •  Lets  you  debug  your  program  amer  it  crashes  

Slide 94

Slide 94 text

No content

Slide 95

Slide 95 text

pry-­‐debugger   •  break   – Adds  a  breakpoint   •  step/next   – Step  into  or  over  the  next  line     •  conFnue   – Stop  stepping  through    

Slide 96

Slide 96 text

Recommended  plugins   •  pry-­‐plus   – pry-­‐debugger,  pry-­‐rescue,  pry-­‐stack_explorer   – pry-­‐doc,  documentaFon  for  C  methods   – pry-­‐docmore,  documentaFon  for  ruby  syntax   – bond,  tab  compleFon  for  Hash#[],  etc.   – jist,  IntegraFon  with  gist.github.com   •  pry-­‐rails   – makes  “rails  c”  use  pry!  

Slide 97

Slide 97 text

• 60%  of  your  Fme  is  spent   debugging   • use  binding.pry  

Slide 98

Slide 98 text

QuesFons?!   •  Pry  (@pryrepl)   – h4p://pryrepl.org   – irc://irc.freenode.net/#pry   – type  “help”  in  pry  :)   •  Conrad  Irwin  (@ConradIrwin)   – h4p://cirw.in   – irc://irc.freenode.net/cirwin