Because I wrote:
p '!!!!!!!!!!!!!!!'
p msg
p '!!!!!!!!!!!!!!!'
too many times already.
dbg
is a minimal, Rust inspired, puts debugging command for Ruby. It provides caller context and formatting helpful in everyday debugging tasks.
bundle add dbg-rb
Alternatively, you can use an inline version of dbg-rb
without adding it to the Gemfile. Check out this post for info on how to do it.
Gem adds a global dbg
method that you can use for puts debugging:
require "dbg-rb"
dbg(User.last.id)
# [web/user_sessions_controller.rb:37] User.last.id = 1972
It appends a caller file, line info and source expression to the debug output.
Hash values are pretty printed:
dbg(User.last.as_json)
# [web/users_controller.rb:10] User.last.as_json = {
# "id": 160111,
# "team_id": 1,
# "pseudonym": "Anonymous-CBWE",
# ...
# }
You can color the output:
config/initializers/dbg_rb.rb
require "dbg-rb"
DbgRb.color_code = 33
# 31 red
# 32 green
# 33 yellow
# 34 blue
# 35 pink
# 36 light blue
It's yellow by default. You can disable colors by running:
DbgRb.color_code = nil
dbg(User.last(2).map(&:as_json))
If it does not stand out enough, you can enable dbg
highlighting:
config/initializers/dbg_rb.rb
require "dbg-rb"
DbgRb.highlight!("🎉💔💣🕺🚀🧨🙈🤯🥳🌈🦄")
Contributions & ideas very welcome!