Autoload 'yaml' in the to_yaml methods

This should add some convenience to users as they don't need to
explicitly load the yaml library before using these methods.