class BigEar::Recorder

Public Class Methods

new(object) click to toggle source
# File lib/big_ear.rb, line 20
def initialize(object)
  @log = []
  @object = object
end

Public Instance Methods

start() click to toggle source
# File lib/big_ear.rb, line 25
def start
  @trace = TracePoint.trace(:return) do |tp|
    next unless tp.self.object_id == @object.object_id
    params_values = tp.self.method(tp.method_id).parameters.map(&:last).map do |param|
      {param => tp.binding.local_variable_get(param)}
    end
    @log.append("method: #{tp.callee_id}, params: #{params_values}, ret_val: #{tp.return_value}")
  end
end
stop() click to toggle source
# File lib/big_ear.rb, line 35
def stop
  @trace&.disable
  @trace = nil
  
  log = @log
  @log = []
  
  log
end