debugging with pry
TRANSCRIPT
Debugging with pry
❤
Murilo Capanema - 2015
Who Am I?GitHub: mcapanema
BankFacil (We are Hiring!)
Murilo Capanema - 2015
What is pry ?Pry is a powerful alternative to the standard IRB shell for Ruby.
Murilo Capanema - 2015
Why pry ?Features:
4 syntax highlighting;
4 flexible plugin architecture;
4 runtime invocation and source and documentation browsing;
Murilo Capanema - 2015
Why not to use pry ?
Murilo Capanema - 2015
Murilo Capanema - 2015
What really is pry ?One line of ruby:
def repl loop{ puts eval $stdin.readline}end
Murilo Capanema - 2015
A little bit of REPLReadEvalPrintLoop
Murilo Capanema - 2015
A little bit of REPLREPL with Tests
4 REPL first !;
4 Record what the code should do ";
4 Write a code that works first time #;
Murilo Capanema - 2015
Why REPL ?REPL or Debugger Driven Development helps you to reach a code that works pretty quickly
Murilo Capanema - 2015
Backing to pryrequire 'pry'binding.pry
Murilo Capanema - 2015
Pry and his friends4 pry-stack-explorer;
4 pry-debugger;
4 pry-rescue;
4 pry-doc;
4 pry-git;
4 helpMurilo Capanema - 2015
Pry magicsls
[1] pry(main)> lsself.methods: inspect to_slocals: _ __ _dir_ _ex_ _file_ _in_ _out_ _pry_[2] pry(main)>
Murilo Capanema - 2015
Pry magicsls
[1] pry(main)> ls Kernelconstants: RUBYGEMS_ACTIVATION_MONITORKernel.methods: Array Rational abort block_given? exit global_variables open putc require sprintf trace_var Complex String ap caller exit! iterator? p puts require_relative srand trap Float __callee__ at_exit caller_locations fail lambda pp raise select syscall untrace_var Hash __dir__ autoload catch fork load print rand set_trace_func system warn Integer __method__ autoload? eval format local_variables printf readline sleep test Pathname ` binding exec gets loop proc readlines spawn throwKernel#methods: !~ clone frozen? kind_of? public_methods tainted? <=> debugger hash method public_send tap === define_singleton_method inspect methods remove_instance_variable to_enum =~ display instance_of? nil? respond_to? to_s ai dup instance_variable_defined? object_id send trust awesome_inspect enum_for instance_variable_get pretty_inspect singleton_class untaint awesome_print eql? instance_variable_set private_methods singleton_method untrust byebug extend instance_variables protected_methods singleton_methods untrusted? class freeze is_a? public_method taint[2] pry(main)>
Murilo Capanema - 2015
Pry magics$ - show-source
[1] pry(main)> $ Kernel#puts
From: io.c (C Method):Owner: KernelVisibility: privateNumber of lines: 8
static VALUErb_f_puts(argc, argv) int argc; VALUE *argv;{ rb_io_puts(argc, argv, rb_stdout); return Qnil;}[2] pry(main)>
Murilo Capanema - 2015
Pry magics$ - show-source
[1] pry(main)> $ Hash
From: /home/vagrant/.rvm/rubies/ruby-2.1.3/lib/ruby/2.1.0/pp.rb @ line 369:Class name: HashNumber of lines: 9
class Hash # :nodoc: def pretty_print(q) # :nodoc: q.pp_hash self end
def pretty_print_cycle(q) # :nodoc: q.text(empty? ? '{}' : '{...}') endend[2] pry(main)>
Murilo Capanema - 2015
Pry magics? - show-doc
[1] pry(main)> ? Object
From: /home/vagrant/.rvm/gems/ruby-2.1.3/gems/awesome_print-1.2.0/lib/awesome_print/core_ext/object.rb @ line 1:Class name: ObjectNumber of monkeypatches: 6. Use the `-a` option to display all available monkeypatchesNumber of lines: 5.........[2] pry(main)>
Murilo Capanema - 2015
Pry magicsbreak
[1] pry(main)> break method_nameBreakpoint 1: /path/to/file.rb @ line 1 (Enabled):.........[2] pry(main)>
Murilo Capanema - 2015
Pry magicstry-again
[1] pry(main)> try-again[2] pry(main)>
Murilo Capanema - 2015
Pry magicsstep/next
[1] pry(main)> step[2] pry(main)> next
Murilo Capanema - 2015
Pry magicsplay
[1] pry(main)> play -l 1[2] pry(main)>
Murilo Capanema - 2015
Pry magicsedit [OPTIONS]
4 -e Open editor on last exception raised
4 -m Open editor on a given method
4 -c Open editor on current method
[1] pry(main)> edit -m method_name[2] pry(main)>
Murilo Capanema - 2015
Pry magicsup
[1] pry(main)> up[2] pry(main)>
Murilo Capanema - 2015
Pry magicsdown
[1] pry(main)> down[2] pry(main)>
Murilo Capanema - 2015
Pry magics@ - whereami
[1] pry(Kernel):1> cd Kernel#puts[2] pry(Kernel):2> @Inside Kernel.[3] pry(Kernel):2>
Murilo Capanema - 2015
Debugging4 Reproduce locally;
4 Find the problem;
4 Fix it;
Murilo Capanema - 2015
More pry magicswtf - _ex_.backtrace
[1] pry(Kernel):1> wtf?.........[2] pry(Kernel):2>
Murilo Capanema - 2015
Further Readinghttps://www.youtube.com/watch?v=D9j_Mf91M0Ihttps://www.youtube.com/watch?v=4hfMUP5iTq8https://github.com/nixme/jazz_handshttp://pryrepl.org/
Murilo Capanema - 2015
FinGitHub: mcapanema
Seriously We are Hiring!
Murilo Capanema - 2015