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 391
def define_proxy_call(code_generator, name, target, parameters, *call_args, namespace))
mangled_name = name
unless NAME_COMPILABLE_REGEXP.match?(name)
mangled_name = "__temp__#{name.unpack1("h*")}"
end
code_generator.define_cached_method(name, as: mangled_name, namespace: namespace) do |batch|
call_args.map!(&:inspect)
call_args << parameters if parameters
body = if CALL_COMPILABLE_REGEXP.match?(target)
"self.#{target}(#{call_args.join(", ")})"
else
call_args.unshift(":'#{target}'")
"send(#{call_args.join(", ")})"
end
modifier = parameters == FORWARD_PARAMETERS ? "ruby2_keywords " : ""
batch <<
"#{modifier}def #{mangled_name}(#{parameters || ''})" <<
body <<
"end"
end
end