YAML to anchor same strings in dumps

Hi, there

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

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

Produces this:

···

---
- aaaaaaaaaa
- aaaaaaaaaa

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

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

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

Thanks,
Gennady.

Found a solution:

module ComplexYamlObject
  def is_complex_yaml?
    true
  end
end

s = 'a' * 10
s.extend ComplexYamlObject
puts [ s, s ].to_yaml

Then the output will be just as I originally wanted:

···

-----Original Message-----
From: Gennady Bystritsky [mailto:Gennady.Bystritsky@quest.com]
Sent: Thursday, January 29, 2009 9:32 PM
To: ruby-talk ML
Subject: YAML to anchor same strings in dumps

Hi, there

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

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

Produces this:
---
- aaaaaaaaaa
- aaaaaaaaaa

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

---
- &id001 aaaaaaaaaa
- *id001

Thought somebody might find it useful,
Gennady.