H
Hans Fugal
I have a data structure (Arrays and Hashes mixed in a soup) that is
fairly self-referential, i.e. it has cycles. When I try to do
foo.to_yaml, it complains:
/opt/local/lib/ruby/1.8/yaml.rb:382:in `quick_emit': stack level too
deep (SystemStackError)
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:164:in `to_yaml'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:41:in `node_export'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:41:in `add'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:41:in `to_yaml'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:40:in `each'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:40:in `to_yaml'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:39:in `map'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:39:in `to_yaml'
... 6502 levels...
from /opt/local/lib/ruby/1.8/yaml.rb:387:in `emit'
from /opt/local/lib/ruby/1.8/yaml.rb:387:in `quick_emit'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:107:in `to_yaml'
from ./yaml.rb:43
However, on the small testing scale it works fine:
---
- &id004
name: foo
famc: &id002
parents:
- &id001
name: bar
fams: *id002
famc: &id005
children:
- *id001
- &id003
name: baz
fams: *id002
famc: &id006
children:
- *id003
children:
- *id004
- *id001
- *id003
- *id002
- *id005
- *id006
Is there anything I can do to help the to_yaml method along? Maybe tell
it to be eager about using aliases or something?
fairly self-referential, i.e. it has cycles. When I try to do
foo.to_yaml, it complains:
/opt/local/lib/ruby/1.8/yaml.rb:382:in `quick_emit': stack level too
deep (SystemStackError)
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:164:in `to_yaml'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:41:in `node_export'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:41:in `add'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:41:in `to_yaml'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:40:in `each'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:40:in `to_yaml'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:39:in `map'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:39:in `to_yaml'
... 6502 levels...
from /opt/local/lib/ruby/1.8/yaml.rb:387:in `emit'
from /opt/local/lib/ruby/1.8/yaml.rb:387:in `quick_emit'
from /opt/local/lib/ruby/1.8/yaml/rubytypes.rb:107:in `to_yaml'
from ./yaml.rb:43
However, on the small testing scale it works fine:
---
- &id004
name: foo
famc: &id002
parents:
- &id001
name: bar
fams: *id002
famc: &id005
children:
- *id001
- &id003
name: baz
fams: *id002
famc: &id006
children:
- *id003
children:
- *id004
- *id001
- *id003
- *id002
- *id005
- *id006
Is there anything I can do to help the to_yaml method along? Maybe tell
it to be eager about using aliases or something?