I am still working through Beginning Ruby - From Novice to Professional
and
I’ve run into a snag with this code:
Code that should save YAML data as the local variable yaml_string and
then
convert it into an array of Person objects
require ‘yaml’
class Person
attr_accessor :name, :age
end
yaml_string = <<END_OF_DATA
- !ruby/object:Person
age: 45
name: Fred Bloggs - !ruby/object:Person
age: 23
name: Laura Smith
END_OF_DATA
test_data = YAML::load(yaml_string)
puts test_data[0].name
puts test_data[1].name
#End of code
Instead it raises this ArgumentError:
ruby grab.rb :
/usr/local/lib/ruby/1.8/yaml.rb:133:in load': syntax error on line 2, col 3:
age: 45’ (ArgumentError)
from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load’
from grab.rb:17
Is there something wrong with the code example? Other functions using
YAML
seem to work fine. Is this the sort of thing that I should mention on a
YAML
mailing list?
Brian