YAML to anchor same strings in dumps

G

Gennady Bystritsky

Hi, there

Is there any way to make YAML alias same strings in dumps? The following co=
de fragment:

require 'yaml'
s =3D 'a' * 10
puts [ s, s ].to_yaml

Produces this:
---
- aaaaaaaaaa
- aaaaaaaaaa

While I need:
---
- &id001 aaaaaaaaaa
- *id001

Interestingly, if I define s as:
s =3D [ 'a' * 10 ]

The output is aliased just fine:
---
- &id001
- aaaaaaaaaa
- *id001

Thanks,
Gennady.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top