On Wed, Aug 22, 2012 at 11:18 PM, SASADA Koichi <ko1 / atdot.net> wrote:
> I understand that TracePoint.new API improves flexibility.  But it is
> more difficult to retrieve it.  For example, users need to consider when
> the trace activate.
>
> And I doubt that the flexibility helps users.  Any use-case?

The advantage comes if you want to setup a tracepoint prior to
activating it, say when something triggers a callback for example. If
we can't pre-build the tracepoint, then we will have to store the
events and procedure separately before applying it and then cache the
result -- it just makes it a little less straight-forward to
implement. A super simplistic example:

  class MyPoint
    def initialize(*events, &block)
      @trace = TracePoint(*events, &block)
    end
    def trigger!
      @trace.on unless @trace.on?
    end
  end

vs.

  class MyPoint
    def initialize(*events, &block)
      @events = events
      @block = block
    end
    def trigger!
      @trace ||=TracePoint.trace(*@events, &@block)
      @trace.on unless @trace.on?
    end
  end

And what about creating a TracePoint and passing it as an argument
(e.g. IOC pattern)? Without new we have to create it and turn it off
real quick first?