---
# System prepended metadata

title: 2022 年 10 月 - 如何在 Ruby 裡面除錯

---

2022 年 10 月 - 如何在 Ruby 裡面除錯
===

https://bit.ly/3TB6Jjs
![](https://i.imgur.com/7TfUm81.png)


靜態型別的語言

需要 debug 工具的原因
變數被改變

https://github.com/rom-rb/rom-sql/issues/389

```ruby=
trace = TracePoint.new(:return) do |tp| 
  pp [tp, tp.path, tp.method_id] 
  tp.binding.pry if tp.path.include?('commands/create.rb')
end

trace.enable { UserRepository.new.create(name: 'Aotoki')

```

https://ruby-doc.org/core-2.5.1/Binding.html
binding 是 private method

https://github.com/ruby/debug
https://st0012.dev/from-byebug-to-ruby-debug
https://github.com/ViewComponent/view_component/pull/1536

找到中間出錯的變化
key word: i、bt