Skip to content

Instantly share code, notes, and snippets.

@levicole
Created July 15, 2010 19:32
Show Gist options
  • Select an option

  • Save levicole/477407 to your computer and use it in GitHub Desktop.

Select an option

Save levicole/477407 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongo_doc'
require 'mustache'
class Person
attr_accessor :name, :age, :interests
def pretty_interests
last = interests.pop
"#{interests.join(", ")} and #{last}"
end
end
collection = MongoDoc::Collection.new('people')
collection.drop
person = Person.new
person.name = "Levi Cole"
person.age = "26"
person.interests = ["ruby", "hipster girls", "guitars", "bluegrass"]
collection.save(person)
levis = collection.where('name' => /Levi/)
template = "Hello, may name is {{name}}, I am {{age}}, and I like {{pretty_interests}}"
puts Mustache.render(template, levis.first)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment