Extract common logic to build mangled method names to a method

This commit is contained in:
Rafael Mendonça França 2023-11-22 17:13:28 +00:00
parent 37833debc6
commit 01492e329f
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948

@ -225,11 +225,8 @@ def alias_attribute_method_definition(code_generator, pattern, new_name, old_nam
method_name = pattern.method_name(new_name).to_s
target_name = pattern.method_name(old_name).to_s
parameters = pattern.parameters
mangled_name = target_name
unless NAME_COMPILABLE_REGEXP.match?(target_name)
mangled_name = "__temp__#{target_name.unpack1("h*")}"
end
mangled_name = build_mangled_name(target_name)
code_generator.define_cached_method(method_name, as: mangled_name, namespace: :alias_attribute) do |batch|
body = if CALL_COMPILABLE_REGEXP.match?(target_name)
@ -419,10 +416,7 @@ def attribute_method_patterns_matching(method_name)
# using the given `extra` args. This falls back on `send`
# if the called name cannot be compiled.
def define_proxy_call(code_generator, name, proxy_target, parameters, *call_args, namespace:)
mangled_name = name
unless NAME_COMPILABLE_REGEXP.match?(name)
mangled_name = "__temp__#{name.unpack1("h*")}"
end
mangled_name = build_mangled_name(name)
call_args.map!(&:inspect)
call_args << parameters if parameters
@ -445,6 +439,16 @@ def define_proxy_call(code_generator, name, proxy_target, parameters, *call_args
end
end
def build_mangled_name(name)
mangled_name = name
unless NAME_COMPILABLE_REGEXP.match?(name)
mangled_name = "__temp__#{name.unpack1("h*")}"
end
mangled_name
end
class AttributeMethodPattern # :nodoc:
attr_reader :prefix, :suffix, :proxy_target, :parameters