Is there a way to use a keystroke to invoke the pry ruby gem? -
i thinking how great able run programme , nail keystroke invoke pry , debug. maybe there gem out there injects binding.pry
dynamically during runtime don't know about. if there isn't, how create keystroke inserts binding.pry
before next line of ruby script execute?
assuming posix os, seek adding signal handler in ruby program. ruby documentation gives illustration of utilize case:
.. process may trap usr1 signal , utilize toggle debugging (http://www.ruby-doc.org/core-2.1.3/signal.html)
signal.trap('usr1') binding.pry end
then, send signal:
kill -s sigusr1 [pid]
edit: more finish example: application.rb
my naïve suggestion above fail threaderror: current thread not owner
. here's improve illustration using global $debug
flag.
#!/usr/bin/env ruby require 'pry' $debug = false signal.trap('usr1') puts 'trapped usr1' $debug = true end class application def run while true print '.' sleep 5 binding.pry if $debug end end end application.new.run
this seems work best when application.rb running in foreground in 1 shell, , send sigusr1 signal separate shell.
tested in mac os 10.9.5. ymmv.
ruby pry
No comments:
Post a Comment