YAML - how to encode an empty string

Learned something interesting (to me) today.

In a fixture file I’m using to test some db code, I need a field to
contain an empty string. I had no idea how to encode that in YAML. I
checked the faq but it consists of one entry about tabs. :slight_smile:

I also searched this list and the Rails list going back to Jan 2005
and came up dry.

irb to the rescue:

cremes$ irb
irb(main):001:0> require ‘yaml’
=> true
irb(main):002:0> empty = “”
=> “”
irb(main):003:0> empty.to_yaml
=> “— “”\n”

I put that into my fixture file (just the “”) and everything is
peachy. Next time I’ll experiment with irb first.

cr

On May 30, 2006, at 11:23 PM, [email protected] wrote:

cr

and for even quicker checking of stuff like this:
% ruby -ryaml -e ‘y “”’
— “”