DEV Community

Burdette Lamar
Burdette Lamar

Posted on

2 2

Custom Handlers for Ruby Gem debug_helper

My Ruby gem debug_helper supports printf-style debugging by explicating a given object (sometimes recursively).
The documentation is over at GitHub project debug_helper.

So far I've implemented handling for many of the more commonly-used classes in the core, and for a few classes in the standard library
Now I'm looking at how to implement a custom handler -- that is, a FooHandler class for your very own class Foo.

Basically, the custom handler needs to specify which methods to call for the explication, along with any required arguments.

Right now I'm expressing that data as an array of arrays:

[
  # Method that takes no argument.
  [:foo],
  # Method that takes arguments.
  [:bar, arg0, arg1]
]
Enter fullscreen mode Exit fullscreen mode

I'm considering allowing more convenience, which also would add complexity:

[
  # Method that takes no argument is just a Symbol.
  :foo,
  # Method that takes arguments can be a an Array, as before.
  [:bar, arg0, arg1],
  # Method that takes arguments can be a 1-key Hash (method and arguments).
  :baz => [arg0, arg1],
]
Enter fullscreen mode Exit fullscreen mode

Opinions?

Neon image

Serverless Postgres in 300ms (❗️)

10 free databases with autoscaling, scale-to-zero, and read replicas. Start building without infrastructure headaches. No credit card needed.

Try for Free →

Top comments (0)

Jetbrains image

Is Your CI/CD Server a Prime Target for Attack?

57% of organizations have suffered from a security incident related to DevOps toolchain exposures. It makes sense—CI/CD servers have access to source code, a highly valuable asset. Is yours secure? Check out nine practical tips to protect your CI/CD.

Learn more

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay