pry at the ruby drink-up of sophia, february 2012

13
Philippe Antras @_philant_ A quick overview

Upload: rivierarb

Post on 03-Jul-2015

1.135 views

Category:

Technology


3 download

DESCRIPTION

Presented at the Ruby Drink-up of Sophia Antipolis on the 7th of February 2012 by Philippe Antras (@_philant_).

TRANSCRIPT

Page 1: Pry at the Ruby Drink-up of Sophia, February 2012

Philippe Antras @_philant_

A quick overview

Page 2: Pry at the Ruby Drink-up of Sophia, February 2012

Pry

REPLCan be invoked at runtimeObject explorationSource and documentation accessShell command executionGist integration - not shown todaySyntax highlighting, completionExtensible: plugin, commands - not shown todayRemote session with pry-remote gem and DrB

http://pry.github.com

Page 3: Pry at the Ruby Drink-up of Sophia, February 2012

> gem install pry

Page 4: Pry at the Ruby Drink-up of Sophia, February 2012

Some Pry commands

show-docshow-methodhistory

play -f <file>

edit <file>edit [input buffer]

ri Array#each

space to escape command:pry(main)> cat = "fido"

<your commands here>

To get a list of all commands:Pry(main)> help

Page 5: Pry at the Ruby Drink-up of Sophia, February 2012

Pry interactions

● ;● !● edit● <space>● _ <underscore>● history ● history --replay 101..105

Page 6: Pry at the Ruby Drink-up of Sophia, February 2012

shell commands

Pry assumes commands prefixed with a dot are shell commands

pry(main)> .ls -lpry(main)> .svn update

pry(main)> .cat #{temp_file}

pry(main)> shell-mode #limited completion

Page 7: Pry at the Ruby Drink-up of Sophia, February 2012

Object explorationpry(main)> pry-versionPry version 0.9.7.4 on Ruby 1.8.7pry(main)> cd Prypry(Pry)> lspry(Pry)> cd @historypry(Pry)> ls -mpry(Pry)> show-doc savepry(Pry)> show-method savepry(Pry)> filename = 'history'pry(Pry)> save filenamepry(Pry)> .cat #{filename}pry(Pry)> cd @historypry(Pry::History)> p sizepry(Pry::History)> puts sizepry(Pry::History)> nestingpry(Pry::History)> cd ../..pry(main)

Page 8: Pry at the Ruby Drink-up of Sophia, February 2012

debugging with Pryruntime invocation

binding.pry

<object>.pry

whereami

Page 9: Pry at the Ruby Drink-up of Sophia, February 2012

Documentation and source browsing

install the pry-doc plugin:> gem install pry-doc

pry(main)> a = [1, 2, 3]pry(main)> ls a -mpry(main)> show-doc a.nitems pry(main)> ls Array -Mpry(main)> show-doc Array#shelljoin pry(main)> show-method Array#shelljoin

Page 10: Pry at the Ruby Drink-up of Sophia, February 2012

Pry as rails console

1. gemfile:gem "pry", :group => :development

2. bundle install3. config/environment/development.rb

silence_warnings do require "pry" IRB = Pryend

4. rails consolepry(main)>

Page 11: Pry at the Ruby Drink-up of Sophia, February 2012

Pry customization

~/.pryrc and ./.pryrc files

Pry.config.inputPry.config.promptPry.config.outputPry.config.printPry.config.exception_handlerPry.config.colorPry.config.pager

Page 12: Pry at the Ruby Drink-up of Sophia, February 2012

Room for improvement

Pry 0.9.8.1

● no completion everywhereno file/path completion on shell commandsshell-mode

● how to retrieve the output of a shell command● object exploration does not support

pwd # use nestingcd -

● cd .. issued from top level context exits # fixed in 0.9.8.1● issue with rspec - binding.pry => NULL pointer given

Page 13: Pry at the Ruby Drink-up of Sophia, February 2012

Thank you.