I'm working on making my first gem, which is not a Rails app, is a tic-tac-toe library with some AI in it, so I can play a computer opponent that will never lose and force a win if possible.
Right now I am trying to debug the attack strategy in the AI, but I can't seem to figure out how to get pry-byebug working in my test script, specfically, have the debugging commands like step
, next
, etc. work upon hitting a binding.pry
.
The gem, named smart-tac-toe, has the following directory structure:
$ ls smart-tac-toe
example Gemfile Gemfile.lock Guardfile lib LICENSE.txt Rakefile README.md smart_tac_toe.gemspec spec tmp
As you can see above, there is an 'example' directory in my gem which contains "example.rb", where I use the classes I've made.
However, when I use binding.pry
and try to use step
and next
, the Pry session just exits and the script keeps running.
In my smart_tac_toe.gemspec file, I clearly have pry-byebug:
spec.add_development_dependency "pry-byebug", '~>2.0.0'
and at the top of my example.rb file, I have tried requiring the proper gems:
require 'pry'
require 'pry-byebug'
require "../lib/smart_tac_toe.rb"
I am using Ruby 2.1.1p76 , the repo for this gem is located at https://github.com/discotroll65/smart_tac_toe
Also, though putting binding.pry into my example script does throw me into a debugging session, initially it is in a reading mode, and I have to press q to exit that before I can start doing repl stuff. Any thoughts as to why this may be?
Ok, looking into this more I realized (I think...still kind of new to the game) a couple things --
1.) If you want to if have
require 'pry'
at the top of your ruby file and have it work in general, it would help to install it in your development environment using your terminal:
user@machine/currentdirectory/$ gem install pry
likewise with pry-byebug:
user@machine/currentdirectory/$ gem install pry-byebug
2.) The real answer to my initial question is to use
byebug
in my script as the debugging hook, instead of
binding.pry
(thanks @mtm for the suggestion!)
when I do use byebug though, while step
and next
work properly, the REPL it throws me into doesn't have any color, and isn't as nice in general...anyway to fix that?