8000 GitHub - pawurb/dbg-rb: Minimal, Rust-inspired, puts debugging helper adding source expression, file and line number info.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
/ dbg-rb Public

Minimal, Rust-inspired, puts debugging helper adding source expression, file and line number info.

License

Notifications You must be signed in to change notification settings

pawurb/dbg-rb

Repository files navigation

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

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.

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

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

Status

Contributions & ideas very welcome!

About

Minimal, Rust-inspired, puts debugging helper adding source expression, file and line number info.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0