Method: Iri#fragment

Defined in:
lib/iri.rb

#fragment(val) ⇒ Iri

Replaces the fragment part of the URI (the part after #).

Examples:

Setting a fragment

Iri.new('https://example.com/page').fragment('section2')
# => "https://example.com/page#section2"

Parameters:

  • val (String)

    New fragment to set, like “section2”

Returns:

  • (Iri)

    A new Iri instance

Raises:

  • (ArgumentError)

See Also:



296
297
298
299
300
301
302
# File 'lib/iri.rb', line 296

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