Method: Addressable::URI#user=

Defined in:
lib/addressable/uri.rb

#user=(new_user) ⇒ Object

Sets the user component for this URI.

Parameters:

  • new_user (String, #to_str)

    The new user component.



970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
# File 'lib/addressable/uri.rb', line 970

def user=(new_user)
  if new_user && !new_user.respond_to?(:to_str)
    raise TypeError, "Can't convert #{new_user.class} into String."
  end
  @user = new_user ? new_user.to_str : nil

  # You can't have a nil user with a non-nil password
  if password != nil
    @user = EMPTY_STR unless user
  end

  # Reset dependent values
  @userinfo = nil
  @normalized_userinfo = NONE
  @authority = nil
  @normalized_user = NONE
  remove_composite_values

  # Ensure we haven't created an invalid URI
  validate()
end