class Hash

def to_query(namespace = nil)

Experimental RBS support (using type sampling data from the type_fusion project).

def to_query: (?nil namespace) -> String

This signature was generated using 60 samples from 2 applications.

are sorted lexicographically in ascending order.
The string pairs "key=value" that conform the query string

# => "user%5Bname%5D=David&user%5Bnationality%5D=Danish"
{name: 'David', nationality: 'Danish'}.to_query('user')

An optional namespace can be passed to enclose key names:

# => "name=David&nationality=Danish"
{name: 'David', nationality: 'Danish'}.to_query

query string:
Returns a string representation of the receiver suitable for use as a URL
def to_query(namespace = nil)
  query = filter_map do |key, value|
    unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
      value.to_query(namespace ? "#{namespace}[#{key}]" : key)
    end
  end
  query.sort! unless namespace.to_s.include?("[]")
  query.join("&")
end