Class: Easytrace

Inherits:
Object
  • Object
show all
Defined in:
lib/easytrace.rb,
lib/easytrace/version.rb

Constant Summary collapse

VERSION =
"0.1.0"
@@DEFINED_METHODS =
[:initialize, :all_enable, :all_disable].freeze

Instance Method Summary collapse

Constructor Details

#initialize(*args, &blk) ⇒ Easytrace

Returns a new instance of Easytrace.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/easytrace.rb', line 4

def initialize(*args, &blk)
    @trace ||= []

    args.each do |symbol|
        @trace << TracePoint.new(symbol) do |tr| 
            unless tr.defined_class != 'Easytrace' && @@DEFINED_METHODS.include?(tr.method_id)
                case tr.event
                when :call
                    p "#{tr.method_id}: started!"
                when :return
                    p "#{tr.method_id}: stopped!"
                end
            end
        end
    end

    all_enable
    yield if block_given?
end