instance method define_proxy_call

Ruby on Rails 7.0.10

Since v5.2.8.1 Private

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

define_proxy_call(code_generator, name, target, parameters, *call_args, namespace:)

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.

Parameters

code_generator req
name req
target req
parameters req
call_args rest
namespace keyreq
Source
# File activemodel/lib/active_model/attribute_methods.rb, line 383
        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}_#{target}") 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

Defined in activemodel/lib/active_model/attribute_methods.rb line 383 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveModel::AttributeMethods::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close