Forum: Ruby YAML symbols

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5fbe9a552e00ab79ef99a83426ac3767?d=identicon&s=25 Alexy Khrabrov (braver)
on 2007-04-19 08:20
(Received via mailing list)
YAML writes out Ruby symbols as !ruby/sym, e.g. :name => 'John'
becomes

!ruby/sym name: John

I write out megabytes of data, so I played with replacing !ruby/sym
with a simple colon:

:name: John

-- and it gets loaded back just as the !ruby/sym version!

Is there a way to instruct YAML to dump plain colon ':' instead of "!
ruby/sym "?  Is reading back my version a guaranteed behavior?

Cheers,
Alexy
8bc543795b502900b5333aea73ad5533?d=identicon&s=25 Eden Li (edenli)
on 2007-04-19 09:29
(Received via mailing list)
Weird... which version of YAML are you using?  It doesn't generate !
ruby/sym for me:

$ ruby -v -r yaml -e 'puts({:name => "John", :yaml_version =>
YAML::VERSION}.to_yaml)'
ruby 1.8.4 (2005-12-24) [i486-linux]
---
:yaml_version: "0.60"
:name: John
833bc92fe8f46a9bfebae5afb65f7507?d=identicon&s=25 Swanand Deodhar (swanand)
on 2007-04-19 13:22
(Received via mailing list)
On Apr 19, 12:28 pm, eden li <eden...@gmail.com> wrote:
> On Apr 19, 2:20 pm, braver <delivera...@gmail.com> wrote:
>
> > -- and it gets loaded back just as the !ruby/sym version!
>
> > Is there a way to instruct YAML to dump plain colon ':' instead of "!
> > ruby/sym "?  Is reading back my version a guaranteed behavior?
>
> > Cheers,
> > Alexy


Hi!
  Same here!  It is not placing ! in my case as well. As per the
YAML.rb documentation it should.
This topic is locked and can not be replied to.