Repository: rails/rails
File: actionview/lib/action_view/helpers/url_helper.rb (Ruby)

Code before:
      #
      # We can also pass in the symbol arguments instead of strings.
      #
      def current_page?(options = nil, check_parameters: false, method: :get, **options_as_kwargs)
        unless request
          raise "You cannot use helpers that need to determine the current " \
                "page unless your view context provides a Request object " \
                "in a #request method"
        end

        options ||= options_as_kwargs
        if options.is_a?(Hash)
          check_parameters ||= options.delete(:check_parameters)
          method ||= options.delete(:method)
        end

        method_matches = if method == :get
          request.get? || request.head?
        else
          request_method = request.method.downcase.to_sym
          if method.is_a?(Array)
            method << :head if method.include?(:get)
            method.include?(request_method)
          else
            method == request_method
          end
        end
        return false unless method_matches

        url_string = URI::RFC2396_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)

        # We ignore any extra parameters in the request_uri if the
        # submitted URL doesn't have any either. This lets the function
        # work with things like ?order=asc
        # the behavior can be disabled with check_parameters: true
        request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
        request_uri = URI::RFC2396_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)

        if %r{^\w+://}.match?(url_string)
          request_uri = +"#{request.protocol}#{request.host_with_port}#{request_uri}"
        end

        remove_trailing_slash!(url_string)
        remove_trailing_slash!(request_uri)

        url_string == request_uri
      end

      # Creates an SMS anchor link tag to the specified +phone_number+. When the
      # link is clicked, the default SMS messaging app is opened ready to send a
      # message to the linked phone number. If the +body+ option is specified,

Review comment (suggestion):
The extra nesting of this if statement could probably be removed?
```suggestion
        method_matches = if method == :get
          request.get? || request.head?
        elsif method.is_a?(Array)
          request_method = request.method.downcase.to_sym
          method << :head if method.include?(:get)
          method.include?(request_method)
        else
          method == request_method
        end
```

Or maybe even:
```suggestion
        method_matches = case method
        when :get
          request.get? || request.head?
        when Array
          request_method = request.method.downcase.to_sym
          method << :head if method.include?(:get)
          method.include?(request_method)
        else
          method == request_method
        end
```

Code after:
      #   # => true
      #
      # We can also pass in the symbol arguments instead of strings.
      #
      def current_page?(options = nil, check_parameters: false, method: :get, **options_as_kwargs)
        unless request
          raise "You cannot use helpers that need to determine the current " \
                "page unless your view context provides a Request object " \
                "in a #request method"
        end

        if options.is_a?(Hash)
          check_parameters = options.delete(:check_parameters) { check_parameters }
          method = options.delete(:method) { method }
        else
          options ||= options_as_kwargs
        end

        method_matches = case method
        when :get
          request.get? || request.head?
        when Array
          method.include?(request.method_symbol) || (method.include?(:get) && request.head?)
        else
          method == request.method_symbol
        end
        return false unless method_matches

        url_string = URI::RFC2396_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)

        # We ignore any extra parameters in the request_uri if the
        # submitted URL doesn't have any either. This lets the function
        # work with things like ?order=asc
        # the behavior can be disabled with check_parameters: true
        request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
        request_uri = URI::RFC2396_PARSER.unescape(request_uri).force_encoding(Encoding::BINARY)

        if %r{^\w+://}.match?(url_string)
          request_uri = +"#{request.protocol}#{request.host_with_port}#{request_uri}"
        end

        remove_trailing_slash!(url_string)
        remove_trailing_slash!(request_uri)

        url_string == request_uri
      end

      # Creates an SMS anchor link tag to the specified +phone_number+. When the
      # link is clicked, the default SMS messaging app is opened ready to send a
      # message to the linked phone number. If the +body+ option is specified,
      # the contents of the message will be preset to +body+.