ruby debugging

Table of Contents

pry

# pry-doc make pry have access to ruby core methods,
 gem install pry pry-doc even the C code

help

.pryrc

help
gem-cd -h

doc

s = 'hello'
RUBY_VERSION
__FILE__
$>
$?
show-doc s.each_line
? s.each_line

show-method s.each_line -l
$ s.each_line -l
install-command gist
gist-method s.each_line

find methods

require 'hello_world'
ls HelloWorld
ls HelloWorld -M
ls -h
ls HelloWorld -m
ls HelloWorld -m --grep ^p
ls HelloWorld -mj

cd HelloWorld  #into context of HelloWorld
ls -m
self
show-method say_hello
say_hello
say_hello; #suppress return value

explore

brew install tree

gem-cd hello_world
.pwd
.tree
.cd lib
shell-mode
hist
cd 12
cd Regexp
nesting
cd ..
jump-to 0
exit

editing

show-input #your input buffer
! #clear input buffer
amend-line 2 "hello"

debug ruby file

pry -r ./hello.rb
edit method
biding.pry
whereami
cd .. #next iteration

rails debug

jazz_hands

rails-footnotes

RailsPanel

rails debug

  • 1.8 – ruby-debug
  • 1.9 – debugger,ruby-debug19,debugger2
  • 2.0 – debugger,byebug,debuuger2
    pry -r ./config/environment
    

    or open development.rb

    require 'pry'
    IRB = pry
    

    pry-rails

    gem 'pry-rails'
    bundle
    
    be rails c
    show-routes
    show-models
    

controller

gem 'pry-byebug' # >2.0
gem 'pry-nav' # >1.9

step s
next n
finish f
continue c

break Class#run
break 14
break --condition 4 x>2
break --condition 3

break --delete 3
break
break --show 3

bettererrors

gem 'better_errors' gem 'binding_of_claller'

在view中打印

web-console

gem 'rack-webconsole-pry'

<%= debug @object %>

会将数据直接打印到html页面上.

pow

pry-remote

binding.remote_pry

log

logger.debug "The object is #{@object}"
RAILS_DEFAULT_LOGGER.debug @object
$tail -f log/development.log

terminal

return render :text => "The object is #{@object}"

会将这个信息打印在屏幕上,并且停止当前这个action执行(看不出来,我这里好像没有停,还可以执行接下来的一个render)