Define a method `name` in `mod` that dispatches to `send` using the given
`extra` args. This falls back on `send` if the called name cannot be
compiled.
# File activemodel/lib/active_model/attribute_methods.rb, line 421
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
call_args.map!(&:inspect)
call_args << parameters if parameters
namespace = :"#{namespace}_#{proxy_target}_#{call_args.join("_")}}"
code_generator.define_cached_method(name, as: mangled_name, namespace: namespace) do |batch|
body = if CALL_COMPILABLE_REGEXP.match?(proxy_target)
"self.#{proxy_target}(#{call_args.join(", ")})"
else
call_args.unshift(":'#{proxy_target}'")
"send(#{call_args.join(", ")})"
end
modifier = parameters == FORWARD_PARAMETERS ? "ruby2_keywords " : ""
batch <<
"#{modifier}def #{mangled_name}(#{parameters || ''})" <<
body <<
"end"
end
end