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.
unknown (Guest)
on 2006-05-31 07: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*.

Logan C. (Guest)
on 2006-05-31 09:24
(Received via mailing list)
On May 30, 2006, at 11:23 PM, removed_email_address@domain.invalid 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.