Now that we know how to create a file and read from it, let's learn how to delete a file. It can be done with a single line of code, like this:
File.delete("files-lessons/teams.txt")
Execute this code, and go back to the directory of your file. The file has been removed.
That's all there is to deleting a file. However, you should be careful while using this command as you don't want to accidentally delete a file. Remember, Ruby offers no warning whatsoever before deleting, so make sure you use it carefully.