You can run an HTTP server to serve files out of the current directory but it won’t be that simple and easy. Not even by using WEBrick that you can simplify things in running an HTTP server. It is not that simple and easy to remember things such as that!
But things can be a whole lot different now that Ruby comes into existence. You can do the “un” library easily since it’s a part of the Ruby standard library. So why is the term “un” present? The answer is easy: In order to require a library from the command line using Ruby, you use the –r switch; hence, it becomes ruby –run.
However, you can still face challenges like deploying Ruby programs which is usually pretty much of a “problem”. At some point, you will need to script some actions just to copy files, create directories and many more. Note that every operating system has their own set of commands in order to do these things.
So the Ruby programmers must have a cross-platform way to make things easier and simpler for them—ruby –run. With this, you can utilize run modules like ruby –run –e cp in order to copy files or ruby –run mkdir to create a directory. Now, that’s not all into it for ruby –run –e httpd . –p 9000 command can be exceedingly useful. It can start a WEBrick HTTP server serving the current directory on port 9000, plus it is really easy to remember.
To help you with, here’s the list of modules included within the library:
- If you want to make a new directory
ruby -run -e mkdir — [OPTION] DIRS
- If you want to erase or remove an empty directory
ruby -run -e rmdir — [OPTION] DIRS
- If you want to touch a file, update its last modified time and create a file:
ruby -run -e touch — [OPTION] FILE
- If you want to copy a file from a source to a certain destination:
ruby -run -e cp — [OPTION] SOURCE DEST
- If you want to link target file from link_name, creating a second file system entry for the file without having to create a new copy of the file itself:
ruby -run -e ln — [OPTION] TARGET LINK_NAME
- If you want to change permission of a file:
ruby -run -e chmod — [OPTION] OCTAL-MODE FILE
- If you want to move a file from a source to destination, rename files or copy a file into another directory:
ruby -run -e mv — [OPTION] SOURCE DEST
- If you want to simply delete or erase a file:
ruby -run -e rm — [OPTION] FILE
- If you want to wait until the file is writable but note that only one program should be waiting for the file to be writable in order to avoid race conditions:
ruby -run -e wait_writable — [OPTION] FILE
- If you want to make a makefile for buildinga a C extension:
ruby -run -e mkmf — [OPTION] EXTNAME [OPTION]
- If you want to make an install command that looks like a copy command only that it can modify the file ownership along with the permissions:
ruby -run -e install — [OPTION] SOURCE DEST
- If you want to run an HTTP server to serve the contents of a directory:
ruby -run -e httpd — [OPTION] DocumentRoot