Been working on a MongoDB data mapping utility in Ruby. Figured I could hone my metaprogramming skills. Check out this snippet below.
I ran into an interesting issue when defining dynamic methods for this data model. On every new instance instantiation the methods were being overwritten to return the new data from the mongo document. To fix this I decided to instantiate singleton methods for each document object in ruby. That way everything will be instantiated properly, and returning the data for the corresponding methods properly.