tags:

views:

13

answers:

1
requrie 'yaml'
hash = {:title=>'abc'}
hash.to_yaml

will output:

--- 
title: abc

Is there any method to force the title to be a binary, like:

---
title: !binary|
  5Lit5pa

UPDATE

I'm asking this because I want to dump the data from database to yml files. But the text in the database, contains English and non-English text, and both may have such code:

<% xxx %>

When I use rake db:fixtures:load, there will be an error like method xxx not found.

I can replace '<%' with '<%%' before writing to file, but it's only works for the English text -- If there is any non-English charactors, the content will be binary. When loading back, '<%%' is still '<%%'. I don't find a good solution unless I can force 'to_yaml' always using 'binary' for text.

+1  A: 

The short answer is 'no'.

The long is - override an String#to_yaml (or Object#to_yaml) method with your custom implementation.

zed_0xff
@zed, thank you!
Freewind