|
1 | 1 | require 'power_assert/configuration' |
2 | 2 |
|
3 | | -if defined?(RubyVM) |
4 | | - if PowerAssert.configuration._redefinition |
5 | | - module PowerAssert |
6 | | - # set redefined flag |
7 | | - basic_classes = [ |
8 | | - Integer, Float, String, Array, Hash, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass |
9 | | - ] |
10 | | - |
11 | | - verbose = $VERBOSE |
12 | | - begin |
13 | | - $VERBOSE = nil |
14 | | - [:Fixnum, :Bignum].each do |c| |
15 | | - if Object.const_defined?(c) and (c = Object.const_get(c)) != Integer |
16 | | - basic_classes << c |
| 3 | +if PowerAssert.configuration._redefinition |
| 4 | + module PowerAssert |
| 5 | + # set redefined flag |
| 6 | + basic_classes = [ |
| 7 | + Integer, Float, String, Array, Hash, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass |
| 8 | + ] |
| 9 | + |
| 10 | + basic_operators = [ |
| 11 | + :+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size, |
| 12 | + :empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min, |
| 13 | + # :call (it is just used for block call optimization) |
| 14 | + :&, :|, |
| 15 | + # :default (no specialized instruction for this) |
| 16 | + :pack, :include?, |
| 17 | + ] |
| 18 | + |
| 19 | + basic_classes.each do |klass| |
| 20 | + basic_operators.each do |bop| |
| 21 | + if klass.public_method_defined?(bop) |
| 22 | + refine(klass) do |
| 23 | + define_method(bop) {} |
17 | 24 | end |
18 | 25 | end |
19 | | - ensure |
20 | | - $VERBOSE = verbose |
21 | 26 | end |
| 27 | + end |
22 | 28 |
|
23 | | - basic_operators = [ |
24 | | - :+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size, |
25 | | - :empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min, |
26 | | - # :call (it is just used for block call optimization) |
27 | | - :&, :|, |
28 | | - # :default (no specialized instruction for this) |
29 | | - :pack, :include?, |
30 | | - ] |
31 | | - |
32 | | - basic_classes.each do |klass| |
33 | | - basic_operators.each do |bop| |
34 | | - if klass.public_method_defined?(bop) |
35 | | - refine(klass) do |
36 | | - define_method(bop) {} |
37 | | - end |
38 | | - end |
39 | | - end |
| 29 | + # bypass check_cfunc |
| 30 | + refine BasicObject do |
| 31 | + def ! |
40 | 32 | end |
41 | 33 |
|
42 | | - # bypass check_cfunc |
43 | | - refine BasicObject do |
44 | | - def ! |
45 | | - end |
46 | | - |
47 | | - def == |
48 | | - end |
| 34 | + def == |
49 | 35 | end |
| 36 | + end |
50 | 37 |
|
51 | | - refine Module do |
52 | | - def == |
53 | | - end |
| 38 | + refine Module do |
| 39 | + def == |
54 | 40 | end |
| 41 | + end |
55 | 42 |
|
56 | | - refine Class do |
57 | | - def new |
58 | | - end |
| 43 | + refine Class do |
| 44 | + def new |
59 | 45 | end |
60 | 46 | end |
61 | 47 | end |
62 | | - |
63 | | - # disable optimization |
64 | | - RubyVM::InstructionSequence.compile_option = { |
65 | | - specialized_instruction: false |
66 | | - } |
67 | 48 | end |
| 49 | + |
| 50 | +# disable optimization |
| 51 | +RubyVM::InstructionSequence.compile_option = { |
| 52 | + specialized_instruction: false |
| 53 | +} |
0 commit comments