Ruby 调试踹门

1,577 阅读1分钟

​看了下 TIOBE 2020 年 06 月编程语言排行榜,Swift 排名 11,Ruby 排名 13,而 Objective-C 跌出前 20,曾经的年度明星语言,往事唏嘘。


言归正传,看到 Ruby China 上关于调试工具的贴「调试工具你们是 pry 党还是 byebug 党」,大概有以下几种选择:

  • puts\p

  • pry

  • byebug

  • pry-byebug

  • RubyMine

  • 组合拳党


今天,也学习下总结一下关于 Ruby 的调试。


pry-byebug

单步调试、堆栈导航

https://github.com/deivid-rodriguez/pry-byebug


安装 pry、pry-byebug

gem install pry
gem install pry-byebug

新建 pry_test.rb


执行 ruby pry_test.rb


pry-byebug 命令说明

单步调试

  • break: 管理断点命令

  • continue: 结束 pry 会话,继续执行程序

  • next: Step over to the next line within the same frame. Also takes an optional numeric argument to step multiple lines.

  • step: Step execution into the next line or method. Takes an optional numeric argument to step multiple times.

  • finish: Execute until current stack frame returns.

堆栈导航

  • backtrace: Shows the current stack. You can use the numbers on the left side with the frame command to navigate the stack.

  • up: Moves the stack frame up. Takes an optional numeric argument to move multiple frames.

  • down: Moves the stack frame down. Takes an optional numeric argument to move multiple frames.

  • frame: Moves to a specific frame. Called without arguments will show the current frame.


byebug

https://github.com/deivid-rodriguez/byebug


RubyMine 调试

https://blog.jetbrains.com/ruby/2019/06/debugging-in-rubymine/


此时,你就可以用这个调试工具 Gem 代码,如果你是一个 iOS 开发, 也可以调试你的 Podfile 了。

关注我的小小公众号