Forum: Ruby YAML - how to encode an empty string

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
A0c079a7c3c9b2cf0bffebd84dc578b0?d=identicon&s=25 unknown (Guest)
on 2006-05-31 05:26
(Received via mailing list)
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. :-)

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*.

E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 Logan Capaldo (Guest)
on 2006-05-31 07:24
(Received via mailing list)
On May 30, 2006, at 11:23 PM, wrote:

> cr

and for even quicker checking of stuff like this:
% ruby -ryaml -e 'y ""'
--- ""
This topic is locked and can not be replied to.