@@ -225,28 +225,13 @@ def alias_attribute_method_definition(code_generator, pattern, new_name, old_nam
225
225
method_name = pattern . method_name ( new_name ) . to_s
226
226
target_name = pattern . method_name ( old_name ) . to_s
227
227
parameters = pattern . parameters
228
- mangled_name = target_name
229
228
230
- unless NAME_COMPILABLE_REGEXP . match? ( target_name )
231
- mangled_name = "__temp__#{ target_name . unpack1 ( "h*" ) } "
232
- end
229
+ mangled_name = build_mangled_name ( target_name )
233
230
234
- code_generator . define_cached_method ( method_name , as : mangled_name , namespace : :alias_attribute ) do |batch |
235
- body = if CALL_COMPILABLE_REGEXP . match? ( target_name )
236
- "self.#{ target_name } (#{ parameters || '' } )"
237
- else
238
- call_args = [ ":'#{ target_name } '" ]
239
- call_args << parameters if parameters
240
- "send(#{ call_args . join ( ", " ) } )"
241
- end
231
+ call_args = [ ]
232
+ call_args << parameters if parameters
242
233
243
- modifier = parameters == FORWARD_PARAMETERS ? "ruby2_keywords " : ""
244
-
245
- batch <<
246
- "#{ modifier } def #{ mangled_name } (#{ parameters || '' } )" <<
247
- body <<
248
- "end"
249
- end
234
+ define_call ( code_generator , method_name , target_name , mangled_name , parameters , call_args , namespace : :alias_attribute )
250
235
end
251
236
252
237
# Is +new_name+ an alias?
@@ -419,20 +404,31 @@ def attribute_method_patterns_matching(method_name)
419
404
# using the given `extra` args. This falls back on `send`
420
405
# if the called name cannot be compiled.
421
406
def define_proxy_call ( code_generator , name , proxy_target , parameters , *call_args , namespace :)
407
+ mangled_name = build_mangled_name ( name )
408
+
409
+ call_args . map! ( &:inspect )
410
+ call_args << parameters if parameters
411
+ namespace = :"#{ namespace } _#{ proxy_target } _#{ call_args . join ( "_" ) } }"
412
+
413
+ define_call ( code_generator , name , proxy_target , mangled_name , parameters , call_args , namespace : namespace )
414
+ end
415
+
416
+ def build_mangled_name ( name )
422
417
mangled_name = name
418
+
423
419
unless NAME_COMPILABLE_REGEXP . match? ( name )
424
420
mangled_name = "__temp__#{ name . unpack1 ( "h*" ) } "
425
421
end
426
422
427
- call_args . map! ( &:inspect )
428
- call_args << parameters if parameters
429
- namespace = :"#{ namespace } _#{ proxy_target } _#{ call_args . join ( "_" ) } }"
423
+ mangled_name
424
+ end
430
425
426
+ def define_call ( code_generator , name , target_name , mangled_name , parameters , call_args , namespace :)
431
427
code_generator . define_cached_method ( name , as : mangled_name , namespace : namespace ) do |batch |
432
- body = if CALL_COMPILABLE_REGEXP . match? ( proxy_target )
433
- "self.#{ proxy_target } (#{ call_args . join ( ", " ) } )"
428
+ body = if CALL_COMPILABLE_REGEXP . match? ( target_name )
429
+ "self.#{ target_name } (#{ call_args . join ( ", " ) } )"
434
430
else
435
- call_args . unshift ( ":'#{ proxy_target } '" )
431
+ call_args . unshift ( ":'#{ target_name } '" )
436
432
"send(#{ call_args . join ( ", " ) } )"
437
433
end
438
434
0 commit comments