1
調試時,我通常使用puts some_variable.inspect
來打印(轉儲)變量。但是,我厭倦了每次輸入puts ...inspect
。有沒有更好的方法來打印變量?Rails打印(轉儲)變量
調試時,我通常使用puts some_variable.inspect
來打印(轉儲)變量。但是,我厭倦了每次輸入puts ...inspect
。有沒有更好的方法來打印變量?Rails打印(轉儲)變量
我發現這一點:http://www.ruby-doc.org/core-2.1.3/Kernel.html#method-i-p
p variable
是puts variable.inspect
一個快捷方式。
使用pry調試
#Gemfile
gem 'pry-rails'
@data = {content: 'important'}
#instead of puts @data.inspec
binding.pry
運行的代碼將持有就行了,在這裏binding.pry叫並開始撬終端會話。
pry(main)> @data
=> {:content=>"important"}
pry(main)> cd @data
pry(#<Hash>):1> ls -m
Enumerable#methods:
all? count each_cons entries flat_map map minmax reduce take
any? cycle each_entry find grep max minmax_by reverse_each take_while
chunk detect each_slice find_all group_by max_by none? slice_before zip
collect drop each_with_index find_index inject min one? sort
collect_concat drop_while each_with_object first lazy min_by partition sort_by
必須檢查http://confreaks.com/videos/2864-rubyconf2013-repl-driven-development-with-pry關於如何使用pry進行調試的更多詳細信息 – 2014-10-17 09:37:01