Sometimes it can be helpful to serve local files without writing or configuring a complete web server, for example when prototyping or testing.

For those occasions, here is a simple one-line server function, which may be called from the command line:

$ ruby -rwebrick -e' => 3000, :DocumentRoot => Dir.pwd).start'

This runs the WEBrick server on port number 3000, serving documents from the current working directory.

To make it even shorter, an alias can be created in a shell profile:

# .bash_profile
alias rblocal='ruby -rwebrick -e'\'' => 8000, :DocumentRoot => Dir.pwd).start'\'''

Once added to .bash_profile (.zshrc in Z shell), the file should be re-sourced:

$ source ~/.bash_profile