how can i connect to a mongodb from Ruby code ?
Kir's answer is appropriate if you are working only with Ruby. But if you are developing a Rails app, you likely will want to connect to MongoDB with an ORM such as:
Using an ORM will give you the functionality Rails developers are familiar with in ActiveRecord. See a list of MongoDB Clients on http://ruby-toolbox.com/.