Method: Iri#host

Defined in:
lib/iri.rb

#host(val) ⇒ Iri

Replaces the host part of the URI.

Examples:

Changing the host

Iri.new('https://google.com').host('example.com')
# => "https://example.com"

Parameters:

  • val (String)

    New host to set, like “example.com” or “192.168.0.1”

Returns:

  • (Iri)

    A new Iri instance

Raises:

  • (ArgumentError)

See Also:



237
238
239
240
241
242
243
244
# File 'lib/iri.rb', line 237

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