dbg! Gem Version GH Actions

Dbg base

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.

Installation

Gemfile

gem "dbg-rb"

Usage

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] 1972

It appends a caller file and line info to the debug output.

You can use symbols to output local variable names together with their values:

a = 1
b = 2 

dbg(:a, :b)
# [models/user.rb:22] a = 1
# [models/user.rb:22] b = 2

Hash values are pretty printed:

user = User.last.as_json
dbg(:user)
# [web/users_controller.rb:10 user = {
#   "id": 160111,
#   "team_id": 1,
#   "pseudonym": "Anonymous-CBWE",
#   ...
# }

You can color the output:

config/initializers/dbg_rb.rb

require "dbg-rb"

DbgRb.color_code = 35 
# 31 red 
# 32 green 
# 33 yellow 
# 34 blue 
# 35 pink 
# 36 light blue
user = User.last.as_json.slice("id", "slack_id")
dbg("User last", :user)

Dbg color

If it does not stand out enough, you can enable dbg highlighting:

config/initializers/dbg_rb.rb

require "dbg-rb"

DbgRb.highlight!("πŸŽ‰πŸ’”πŸ’£πŸ•ΊπŸš€πŸ§¨πŸ™ˆπŸ€―πŸ₯³πŸŒˆπŸ¦„")

Dbg emoji

You can also use DbgRb.dbg!(*msgs) directly or wrap it to rename the helper method:

def dd(*msgs)
  DbgRb.dbg!(*msgs)
end

Status

Contributions & ideas very welcome!