Extract out metaclass definition
Extract out _attach_method