runtime: Add class_addMethod()

Also moves out some stuff to functions to be reusable by
class_addMethod().