Skip to content

Commit 5de3d0e

Browse files
authored
Merge pull request #34 from nobu/remove-FixnumBignum
Get rid of obsolete Fixnum and Bignum
2 parents b2feda8 + d6c7fde commit 5de3d0e

File tree

1 file changed

+57
-51
lines changed

1 file changed

+57
-51
lines changed

lib/power_assert/enable_tracepoint_events.rb

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,80 +7,86 @@
77
warn 'power_assert: See https://www.ruby-lang.org/en/news/2016/11/21/ruby-2-3-3-released/ for more details.'
88
end
99

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+
]
1815

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
2722
end
2823
end
24+
ensure
25+
$VERBOSE = verbose
26+
end
2927

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
3336
end
37+
end
3438

35-
_ = Class.new(bug11182) do
36-
alias _fixed? fixed?
37-
protected :_fixed?
39+
refine bug11182 do
40+
def fixed?
3841
end
42+
end
43+
44+
_ = Class.new(bug11182) do
45+
alias _fixed? fixed?
46+
protected :_fixed?
47+
end
3948

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) {}
4755
end
4856
end
4957
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
5866
end
5967
end
6068
end
69+
end
6170

62-
refine Symbol do
63-
def ==
64-
end
71+
refine Symbol do
72+
def ==
6573
end
6674
end
75+
end
6776

68-
# bypass check_cfunc
69-
refine BasicObject do
70-
def !
71-
end
77+
# bypass check_cfunc
78+
refine BasicObject do
79+
def !
80+
end
7281

73-
def ==
74-
end
82+
def ==
7583
end
84+
end
7685

77-
refine Module do
78-
def ==
79-
end
86+
refine Module do
87+
def ==
8088
end
8189
end
82-
ensure
83-
$VERBOSE = verbose
8490
end
8591
end
8692

0 commit comments

Comments
 (0)