Skip to content

Instantly share code, notes, and snippets.

@igaiga
Last active February 11, 2023 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igaiga/838d8e5617c41461d14add0388ab7f2a to your computer and use it in GitHub Desktop.
Save igaiga/838d8e5617c41461d14add0388ab7f2a to your computer and use it in GitHub Desktop.
# https://github.com/st0012/ruby_tracer
Tracer.new(:exception) {}
Tracer.new(:exception).trace {}
Tracer.new(:exception).config(a: true, b: 1, ...).trace {}
Tracer.new(:exception, config_a: true, config_b: 1, ...).trace {}
# The method name "trace" is nice, but maybe a better name?
# "Tracer#trace" seems redundant.
Tracer.new(:call) {}
Tracer.new(:line) {}
tracer = Tracer.new(:call)
tracer.enable or start
...
tracer.disable or finish or suspend
They are similar to TracePoint.
https://docs.ruby-lang.org/ja/latest/class/TracePoint.html#S_NEW
@st0012
Copy link

st0012 commented Feb 11, 2023

IMO, the Tracer API should NOT look like TracePoint's, because they're used in different ways:

  • TracePoint: usually to implement something that'll stay (e.g. a tracer).
  • Tracer: usually to be removed/added frequently, like puts. So it should be short and easy to remember.

And given its frequent-editing need, I'm favoring methods Tracer.trace_call over instances Tracer.new(:call) because the former can be autocompleted in editor or IRB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment