method

generate_method_missing

generate_method_missing(owner, target, allow_nil: nil)
public

No documentation available.

# File activesupport/lib/active_support/delegation.rb, line 150
      def generate_method_missing(owner, target, allow_nil: nil)
        target = target.to_s
        target = "self.#{target}" if RESERVED_METHOD_NAMES.include?(target) || target == "__target"

        if allow_nil
          owner.module_eval <<~RUBY, __FILE__, __LINE__ + 1
            def respond_to_missing?(name, include_private = false)
              # It may look like an oversight, but we deliberately do not pass
              # +include_private+, because they do not get delegated.

              return false if name == :marshal_dump || name == :_dump
              #{target}.respond_to?(name) || super
            end

            def method_missing(method, ...)
              __target = #{target}
              if __target.nil? && !nil.respond_to?(method)
                nil
              elsif __target.respond_to?(method)
                __target.public_send(method, ...)
              else
                super
              end
            end
          RUBY
        else
          owner.module_eval <<~RUBY, __FILE__, __LINE__ + 1
            def respond_to_missing?(name, include_private = false)
              # It may look like an oversight, but we deliberately do not pass
              # +include_private+, because they do not get delegated.

              return false if name == :marshal_dump || name == :_dump
              #{target}.respond_to?(name) || super
            end

            def method_missing(method, ...)
              __target = #{target}
              if __target.nil? && !nil.respond_to?(method)
                raise ::ActiveSupport::DelegationError.nil_target(method, :'#{target}')
              elsif __target.respond_to?(method)
                __target.public_send(method, ...)
              else
                super
              end
            end
          RUBY
        end
      end