在gem的例子脚本中如何使用pry-byebug? [英] How to use pry-byebug in an example script for a gem?

查看:357
本文介绍了在gem的例子脚本中如何使用pry-byebug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力制作我的第一个宝石,这不是一个Rails应用程序,是一个具有一些AI的tic-tac-toe图书馆,所以我可以玩一个永远不会失去的电脑对手,强制赢得可能的。



现在我试图在AI中调试攻击策略,但我似乎无法弄清楚如何在我的测试中工作笨蛋脚本,具体来说,具有如 step next 等调试命令,可以在$ code > bind.pry 。



名为smart-tac-toe的gem具有以下目录结构:

  $ ls smart-tac-toe 
示例Gemfile Gemfile.lock Guardfile lib LICENSE.txt Rakefile README.md smart_tac_toe.gemspec spec tmp

如上所示,我的宝石中有一个example目录,其中包含example.rb我使用我所做的课程。



但是,当我使用 binding.pry 并尝试使用 st ep next ,Pry会话刚刚退出,脚本继续运行。



在我的smart_tac_toe.gemspec文件中,我显然有pry-byebug:

  spec.add_development_dependencypry-byebug,'〜> ; 2.0.0'

在我的example.rb文件的顶部,我已经尝试要求正确的宝石:

  require'pry'
require'pry-byebug'
require../ lib / smart_tac_toe.rb

我使用的是Ruby 2.1.1p76,这个gem的repo位于 https://github.com/discotroll65/smart_tac_toe



此外,尽管将binding.pry放入我的示例脚本会使我进入调试会话,最初它处于阅读模式,我必须按 q 退出,然后才能开始做复制的东西。对于这可能是什么的任何想法?

解决方案

新的游戏)一对夫妇的事情 -



1。)如果你想要有

 需要'pry'

在你的红宝石文件的顶部,一般来说,它将有助于使用您的终端将其安装在您的开发环境中:

  user @ machine / currentdirectory / $ gem install pry 

同样用pry-byebug:

  user @ machine / currentdirectory / $ gem install pry-byebug 

2。)我最初的问题的真实答案是使用

  byebug 

作为调试挂钩,而不是

 code> binding.pry 

(感谢@mtm的建议!)



n我确实使用byebug,而步骤下一个正常工作,REPL它让我进入没有任何颜色,并不总是一样好...无论如何修复?


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?

这篇关于在gem的例子脚本中如何使用pry-byebug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆