|
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 | | - basic_operators = [ |
12 | | - :+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, :length, :size, |
13 | | - :empty?, :nil?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min, |
14 | | - # :call (it is just used for block call optimization) |
15 | | - :&, :|, |
16 | | - # :default (no specialized instruction for this) |
17 | | - :pack, :include?, |
18 | | - ] |
19 | | - |
20 | | - basic_classes.each do |klass| |
21 | | - basic_operators.each do |bop| |
22 | | - if klass.public_method_defined?(bop) |
23 | | - refine(klass) do |
24 | | - define_method(bop) {} |
25 | | - end |
| 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) {} |
26 | 24 | end |
27 | 25 | end |
28 | 26 | end |
| 27 | + end |
29 | 28 |
|
30 | | - # bypass check_cfunc |
31 | | - refine BasicObject do |
32 | | - def ! |
33 | | - end |
| 29 | + # bypass check_cfunc |
| 30 | + refine BasicObject do |
| 31 | + def ! |
| 32 | + end |
34 | 33 |
|
35 | | - def == |
36 | | - end |
| 34 | + def == |
37 | 35 | end |
| 36 | + end |
38 | 37 |
|
39 | | - refine Module do |
40 | | - def == |
41 | | - end |
| 38 | + refine Module do |
| 39 | + def == |
42 | 40 | end |
| 41 | + end |
43 | 42 |
|
44 | | - refine Class do |
45 | | - def new |
46 | | - end |
| 43 | + refine Class do |
| 44 | + def new |
47 | 45 | end |
48 | 46 | end |
49 | 47 | end |
50 | | - |
51 | | - # disable optimization |
52 | | - RubyVM::InstructionSequence.compile_option = { |
53 | | - specialized_instruction: false |
54 | | - } |
55 | 48 | end |
| 49 | + |
| 50 | +# disable optimization |
| 51 | +RubyVM::InstructionSequence.compile_option = { |
| 52 | + specialized_instruction: false |
| 53 | +} |
0 commit comments