Skip to content

Introduce support for keyword arguments #3323

@flavorjones

Description

@flavorjones

The Nokogiri API was largely designed and implemented for Ruby 1.9, which pre-dates keyword argument support and parameter forwarding with .... As a result, many methods are using positional arguments where keyword arguments are probably better.

For example, Nokogiri::XML::Document.parse is declared as:

def parse(string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML)

I would like to update these method signatures to support keyword arguments without dropping support (yet) for positional arguments. In the case of Document.parse, this might look like:

def parse(string_or_io,
          url_ = nil, encoding_ = nil, options_ = XML::ParseOptions::DEFAULT_XML,
          url: url_, encoding: encoding_, options: options_)

I would also like to update the docstrings to describe the keyword arguments, and remove documentation for the positional arguments.

Another example is Nokogiri::XML() which is defined as:

def XML(thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_XML, &block)
  Nokogiri::XML::Document.parse(thing, url, encoding, options, &block)
end

Methods that are forwarding positional arguments should be updated to more cleanly forward either keyword arguments or positional arguments, and avoid redeclaring parameter default values:

def XML(...)
  Nokogiri::XML::Document.parse(...)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions