pry, the good parts

Post on 15-May-2015

1.896 Views

Category:

Documents

6 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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…

What’s Pry?

• “like irb, but better”

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

• An aide for ruby programmers

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

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

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

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

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

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

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

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

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”

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”

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”

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”

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”

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”

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”

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”

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

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

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.

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.

How do I use the Base64 library?

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

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

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

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

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’

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’

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’

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

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

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

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

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

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

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)

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)

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

Why doesn’t my method work?

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

Why doesn’t my method work?

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

Why doesn’t my method work?

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

Why doesn’t my method work?

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

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

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

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]

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”]

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

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

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

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

$

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

Where did that nil come from?

$ subl post.rb$

Where did that nil come from?

$ subl post.rb$ ruby post.rb

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

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

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

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

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

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>

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

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>

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

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

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>

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

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>

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

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>

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

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>

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

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

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

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

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

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

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

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

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>

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)

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

What does ordinalize actually do?

[1] pry(main)>

What does ordinalize actually do?

[1] pry(main)> help gem

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

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

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

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

What does ordinalize actually do?

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

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

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’

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

What does ordinalize actually do?

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

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

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

Configuration

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

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

• Documentation on the wiki

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)

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

top related