Forum: Ruby YAML anchor and alias problem

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.
Cdc7e43669b5b09281eb2acedc74c94b?d=identicon&s=25 unknown (Guest)
on 2008-12-05 17:37
(Received via mailing list)
Hi,
I'm trying to use YAML to load and store a whole bunch of data (with a
lot of repetition). Anchors and aliases seem to be the way froward,
but I am runing into a few problems.

Suppose I have the following YAML document:
---
anchor: &id001
- sample1 :
  name: s1
  freq: 0.27
- sample2 :
  name: s2
  freq: 0.27
alias: *id001

held in a string (str). I then load it

x=YAML.load(str)
=> {"anchor"=>[{"name"=>"s1", "freq"=>0.27, "sample1"=>nil},
{"name"=>"s2", "freq"=>0.27, "sample2"=>nil}], "alias"=>nil}

Why does my alias always come out as nil. Where do I need to put the
anchor in order that the alias picks up the entire list. This is the
output I desire
=> {"anchor"=>[{"name"=>"s1", "freq"=>0.27, "sample1"=>nil},
{"name"=>"s2", "freq"=>0.27, "sample2"=>nil}], "alias"=>
[{"name"=>"s1", "freq"=>0.27, "sample1"=>nil}, {"name"=>"s2",
"freq"=>0.27, "sample2"=>nil}]}

Thanks

Steve
Cdc7e43669b5b09281eb2acedc74c94b?d=identicon&s=25 unknown (Guest)
on 2008-12-05 18:00
(Received via mailing list)
On Dec 5, 4:30 pm, stevegoobermanh...@googlemail.com wrote:
>   freq: 0.27
>
> Steve
Belay that - problem found - I didn't have the indenting right

Steve
This topic is locked and can not be replied to.