class Addressable::URI

def userinfo=(new_userinfo)

Parameters:
  • new_userinfo (String, #to_str) -- The new userinfo component.
def userinfo=(new_userinfo)
  if new_userinfo && !new_userinfo.respond_to?(:to_str)
    raise TypeError, "Can't convert #{new_userinfo.class} into String."
  end
  new_user, new_password = if new_userinfo
    [
      new_userinfo.to_str.strip[/^(.*):/, 1],
      new_userinfo.to_str.strip[/:(.*)$/, 1]
    ]
  else
    [nil, nil]
  end
  # Password assigned first to ensure validity in case of nil
  self.password = new_password
  self.user = new_user
  # Reset dependent values
  remove_instance_variable(:@authority) if defined?(@authority)
  remove_composite_values
  # Ensure we haven't created an invalid URI
  validate()
end