DEV Community 👩‍💻👨‍💻

Burdette Lamar
Burdette Lamar

Posted on

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.
  # 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.
  # 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


Top comments (0)

12 Gorgeous UI Components for Your Design Inspiration

12 Gorgeous UI components for your design inspiration: cards, text, buttons, checkboxes, icons, loaders and menus.