|
7 | 7 | warn 'power_assert: See https://www.ruby-lang.org/en/news/2016/11/21/ruby-2-3-3-released/ for more details.' |
8 | 8 | end |
9 | 9 |
|
10 | | - verbose = $VERBOSE |
11 | | - begin |
12 | | - $VERBOSE = nil |
13 | | - module PowerAssert |
14 | | - # set redefined flag |
15 | | - basic_classes = [ |
16 | | - Fixnum, Float, String, Array, Hash, Bignum, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass |
17 | | - ] |
| 10 | + module PowerAssert |
| 11 | + # set redefined flag |
| 12 | + basic_classes = [ |
| 13 | + Integer, Float, String, Array, Hash, Symbol, Time, Regexp, NilClass, TrueClass, FalseClass |
| 14 | + ] |
18 | 15 |
|
19 | | - basic_operators = [ |
20 | | - :+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, |
21 | | - :length, :size, :empty?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min, :nil? |
22 | | - ] |
23 | | - |
24 | | - bug11182 = Class.new do |
25 | | - def fixed? |
26 | | - true |
| 16 | + verbose = $VERBOSE |
| 17 | + begin |
| 18 | + $VERBOSE = nil |
| 19 | + [:Fixnum, :Bignum].each do |c| |
| 20 | + if Object.const_defined?(c) and (c = Object.const_get(c)) != Integer |
| 21 | + basic_classes << c |
27 | 22 | end |
28 | 23 | end |
| 24 | + ensure |
| 25 | + $VERBOSE = verbose |
| 26 | + end |
29 | 27 |
|
30 | | - refine bug11182 do |
31 | | - def fixed? |
32 | | - end |
| 28 | + basic_operators = [ |
| 29 | + :+, :-, :*, :/, :%, :==, :===, :<, :<=, :<<, :[], :[]=, |
| 30 | + :length, :size, :empty?, :succ, :>, :>=, :!, :!=, :=~, :freeze, :-@, :max, :min, :nil? |
| 31 | + ] |
| 32 | + |
| 33 | + bug11182 = Class.new do |
| 34 | + def fixed? |
| 35 | + true |
33 | 36 | end |
| 37 | + end |
34 | 38 |
|
35 | | - _ = Class.new(bug11182) do |
36 | | - alias _fixed? fixed? |
37 | | - protected :_fixed? |
| 39 | + refine bug11182 do |
| 40 | + def fixed? |
38 | 41 | end |
| 42 | + end |
| 43 | + |
| 44 | + _ = Class.new(bug11182) do |
| 45 | + alias _fixed? fixed? |
| 46 | + protected :_fixed? |
| 47 | + end |
39 | 48 |
|
40 | | - if (bug11182.new.fixed? rescue false) |
41 | | - basic_classes.each do |klass| |
42 | | - basic_operators.each do |bop| |
43 | | - if klass.public_method_defined?(bop) |
44 | | - refine(klass) do |
45 | | - define_method(bop) {} |
46 | | - end |
| 49 | + if (bug11182.new.fixed? rescue false) |
| 50 | + basic_classes.each do |klass| |
| 51 | + basic_operators.each do |bop| |
| 52 | + if klass.public_method_defined?(bop) |
| 53 | + refine(klass) do |
| 54 | + define_method(bop) {} |
47 | 55 | end |
48 | 56 | end |
49 | 57 | end |
50 | | - else |
51 | | - # workaround for https://bugs.ruby-lang.org/issues/11182 |
52 | | - basic_classes.each do |klass| |
53 | | - basic_operators.each do |bop| |
54 | | - if klass.public_method_defined?(bop) |
55 | | - klass.ancestors.find {|i| i.instance_methods(false).index(bop) }.module_eval do |
56 | | - public bop |
57 | | - end |
| 58 | + end |
| 59 | + else |
| 60 | + # workaround for https://bugs.ruby-lang.org/issues/11182 |
| 61 | + basic_classes.each do |klass| |
| 62 | + basic_operators.each do |bop| |
| 63 | + if klass.public_method_defined?(bop) |
| 64 | + klass.ancestors.find {|i| i.instance_methods(false).index(bop) }.module_eval do |
| 65 | + public bop |
58 | 66 | end |
59 | 67 | end |
60 | 68 | end |
| 69 | + end |
61 | 70 |
|
62 | | - refine Symbol do |
63 | | - def == |
64 | | - end |
| 71 | + refine Symbol do |
| 72 | + def == |
65 | 73 | end |
66 | 74 | end |
| 75 | + end |
67 | 76 |
|
68 | | - # bypass check_cfunc |
69 | | - refine BasicObject do |
70 | | - def ! |
71 | | - end |
| 77 | + # bypass check_cfunc |
| 78 | + refine BasicObject do |
| 79 | + def ! |
| 80 | + end |
72 | 81 |
|
73 | | - def == |
74 | | - end |
| 82 | + def == |
75 | 83 | end |
| 84 | + end |
76 | 85 |
|
77 | | - refine Module do |
78 | | - def == |
79 | | - end |
| 86 | + refine Module do |
| 87 | + def == |
80 | 88 | end |
81 | 89 | end |
82 | | - ensure |
83 | | - $VERBOSE = verbose |
84 | 90 | end |
85 | 91 | end |
86 | 92 |
|
|
0 commit comments