# Trouble with YAML::load

**URL:** <https://www.ruby-forum.com/t/trouble-with-yaml-load/147435>\
**Category:** Ruby\
**Created:** [September 1, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/trouble-with-yaml-load/147435 "2008-09-01T19:51:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [September 1, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/trouble-with-yaml-load/147435/1 "2008-09-01T19:51:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [September 1, 2008, 7:59pm UTC](https://www.ruby-forum.com/t/trouble-with-yaml-load/147435/2 "2008-09-01T19:59:13Z")

</div>

On Sep 1, 1:45 pm, “Brian R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Try indenting:

## yaml\_string = \<\<END\_OF\_DATA

- !ruby/object:Person  
age: 45  
name: Fred Bloggs
- !ruby/object:Person  
age: 23  
name: Laura Smith  
END\_OF\_DATA

T.

---

<div class="post-metadata">

**Author:** ![circlefusion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ea666f/32.png) [@circlefusion](https://www.ruby-forum.com/u/circlefusion)\
**Post date:** [September 1, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/trouble-with-yaml-load/147435/3 "2008-09-01T20:08:37Z")

</div>

On Mon, Sep 1, 2008 at 1:52 PM, Trans [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Try indenting:

Thanks!

Brian
