Method: Iri#query

Defined in:
lib/iri.rb

#query(val) ⇒ Iri

Replaces the entire query part of the URI.

Use this method to completely replace the query string. For modifying individual parameters, see #add, #del, and #over.

Examples:

Setting a query string

Iri.new('https://example.com/search').query('q=ruby&limit=10')
# => "https://example.com/search?q=ruby&limit=10"

Parameters:

  • val (String)

    New query string to set, like “a=1&b=2”

Returns:

  • (Iri)

    A new Iri instance

Raises:

  • (ArgumentError)

See Also:



318
319
320
321
322
323
324
# File 'lib/iri.rb', line 318

def query(val)
  raise ArgumentError, "The query can't be nil" if val.nil?
  val = val.to_s
  modify do |c|
    c.query = val
  end
end