I thought I was grasping the concepts of yaml, but I am growing confused as
I am messing with it doing some example coding with it. Here is a gist of my
code.
Loading YAML from a file Problem · GitHub
It works fine until it goes to load the main.yaml file at which point I get
the following error.
yaml1.rb:37:in `<main>': undefined method `width' for
#<String:0x000001010fb9d0> (NoMethodError)
It seems like it should work. Am I just missing something or am I
approaching it wrong.
You're serializing yaml to yaml:
serialized = Square.new(2,3).to_yaml
# save yaml to file
File.open('main.yaml', 'w') do |out|
YAML.dump(serialized, out)
end
% ri YAML.dump
= YAML.dump
(from ruby core)
···
On Feb 8, 2011, at 15:41 , Buddy Lindsey, Jr. wrote:
------------------------------------------------------------------------------
dump( obj, io = nil )
------------------------------------------------------------------------------
Converts obj to YAML and writes the YAML result to io.
File.open( 'animals.yaml', 'w' ) do |out|
YAML.dump( ['badger', 'elephant', 'tiger'], out )
end
If no io is provided, a string containing the dumped YAML is returned.
YAML.dump( :locked )
#=> "--- :locked"