@@ -27,26 +27,28 @@ module Hook
27
27
:>> => "rshift" ,
28
28
:~ => "tilda"
29
29
}
30
- def self . alias_names ( target )
30
+ def self . alias_names ( target , random )
31
+ suffix = "#{ RBS ::Test . suffix } _#{ random } "
32
+
31
33
case target
32
34
when *OPERATORS . keys
33
35
name = OPERATORS [ target ]
34
36
[
35
- "#{ name } ____with__#{ Test . suffix } " ,
36
- "#{ name } ____without__#{ Test . suffix } "
37
+ "#{ name } ____with__#{ suffix } " ,
38
+ "#{ name } ____without__#{ suffix } "
37
39
]
38
40
else
39
41
aliased_target , punctuation = target . to_s . sub ( /([?!=])$/ , '' ) , $1
40
42
41
43
[
42
- "#{ aliased_target } __with__#{ Test . suffix } #{ punctuation } " ,
43
- "#{ aliased_target } __without__#{ Test . suffix } #{ punctuation } "
44
+ "#{ aliased_target } __with__#{ suffix } #{ punctuation } " ,
45
+ "#{ aliased_target } __without__#{ suffix } #{ punctuation } "
44
46
]
45
47
end
46
48
end
47
49
48
- def self . setup_alias_method_chain ( klass , target )
49
- with_method , without_method = alias_names ( target )
50
+ def self . setup_alias_method_chain ( klass , target , random : )
51
+ with_method , without_method = alias_names ( target , random )
50
52
51
53
RBS . logger . debug "alias name: #{ target } , #{ with_method } , #{ without_method } "
52
54
@@ -65,8 +67,8 @@ def self.setup_alias_method_chain(klass, target)
65
67
end
66
68
end
67
69
68
- def self . hook_method_source ( prefix , method_name , key )
69
- with_name , without_name = alias_names ( method_name )
70
+ def self . hook_method_source ( prefix , method_name , key , random : )
71
+ with_name , without_name = alias_names ( method_name , random )
70
72
full_method_name = "#{ prefix } #{ method_name } "
71
73
72
74
[ __LINE__ + 1 , <<RUBY ]
@@ -160,17 +162,19 @@ def #{with_name}(*args, &block)
160
162
end
161
163
162
164
def self . hook_instance_method ( klass , method , key :)
163
- line , source = hook_method_source ( "#{ klass } #" , method , key )
165
+ random = SecureRandom . hex ( 4 )
166
+ line , source = hook_method_source ( "#{ klass } #" , method , key , random : random )
164
167
165
168
klass . module_eval ( source , __FILE__ , line )
166
- setup_alias_method_chain klass , method
169
+ setup_alias_method_chain klass , method , random : random
167
170
end
168
171
169
172
def self . hook_singleton_method ( klass , method , key :)
170
- line , source = hook_method_source ( "#{ klass } ." , method , key )
173
+ random = SecureRandom . hex ( 4 )
174
+ line , source = hook_method_source ( "#{ klass } ." , method , key , random : random )
171
175
172
176
klass . singleton_class . module_eval ( source , __FILE__ , line )
173
- setup_alias_method_chain klass . singleton_class , method
177
+ setup_alias_method_chain klass . singleton_class , method , random : random
174
178
end
175
179
end
176
180
end
0 commit comments