File: enable_tracepoint_events.rb

package info (click to toggle)
ruby-power-assert 2.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 228 kB
  • sloc: ruby: 1,658; makefile: 5; sh: 4
file content (60 lines) | stat: -rw-r--r-- 1,394 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'power_assert/configuration'

if defined?(RubyVM)
  if PowerAssert.configuration._redefinition
    module PowerAssert
      # set redefined flag
      basic_classes = [
        Integer, Float, String, Array, Hash, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass
      ]

      verbose = $VERBOSE
      begin
        $VERBOSE = nil
        [:Fixnum, :Bignum].each do |c|
          if Object.const_defined?(c) and (c = Object.const_get(c)) != Integer
            basic_classes << c
          end
        end
      ensure
        $VERBOSE = verbose
      end

      basic_operators = [
        :+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size,
        :empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min,
        # :call (it is just used for block call optimization)
        :&, :|
      ]

      basic_classes.each do |klass|
        basic_operators.each do |bop|
          if klass.public_method_defined?(bop)
            refine(klass) do
              define_method(bop) {}
            end
          end
        end
      end

      # bypass check_cfunc
      refine BasicObject do
        def !
        end

        def ==
        end
      end

      refine Module do
        def ==
        end
      end
    end
  end

  # disable optimization
  RubyVM::InstructionSequence.compile_option = {
    specialized_instruction: false
  }
end