Generic method

Should close up #92 and pave the way for joyent/node#3192. Currently depends on #144 or #106 being merged, because I wasn't paying attention and I don't know how to rebase it. Tests pass, but I'm still not confident in the patch quality. Review desired.