How does the sub-domain like urls are created in web apps?

Hello,
     I registered in a site called basecamp. After I registered, they
gave me a url like http://xxx.basecamp.com where i have to log in access
my project management. I heard that basecamp is built in ruby on rails.
I couldn't get the point of building a subdomain like url. Can anyone
give some guidance of how to create a sub domain like url using rails?
Thanks in advance

You can use subdomains for various purposes. One is to host different
servers (eg mail.example.com and www.example.com), or to host
different applications (eg blog@example.com and forum@example.com).

I believe Basecamp use it to have nicer URLs. The standard way would
be:
//www.example.com/~rockroll/..., or
//www.example.com/...?user_id=123456

//rockroll.example.com/... looks nicer.

A few links:
http://wiki.rubyonrails.org/rails/pages/HowToUseSubdomainsAsAccountKeys
http://www.jonathansng.com/ruby-on-rails/find-your-rails-subdomains/http://www.railsonwave.com/railsonwave/2007/7/10/howto-put-a-controller-under-a-ssl-subdomain

Christian